Home Web Front-end CSS Tutorial How to solve the problem of invalid adjustment of z-index attribute of div layer

How to solve the problem of invalid adjustment of z-index attribute of div layer

Jun 20, 2018 pm 03:54 PM
z-index

This article mainly introduces the analysis and solutions to the reasons for the invalid adjustment of the z-index attribute of the p layer. Friends in need can refer to the following

z-index is invalid

In the process of doing it , I discovered a very simple problem that many people should encounter. Setting the Z-INDEX attribute is invalid. In CSS, the level can only be changed through code. This attribute is z-index. There is a small prerequisite for z-index to work, that is, the position attribute of the element must be relative, absolute or fixed.

1. The first situation (z-index does not work no matter how high it is set):

There are three conditions for this situation to occur:

1. The position attribute of the parent tag is relative;
2. The question tag has no position attribute (excluding static);
3. The question tag contains a float attribute.

eg: The z-index level does not work. Floating will invalidate the z-index. The code is as follows:

<p style="POSITION: relative; Z-INDEX: 9999">  
<IMG style="FLOAT: left" src="/131101/1A5494I0-0.jpg">  
</p>
Copy after login

There are three solutions (any one is sufficient):

1. Change position: relative to position: absolute;
2. Add position attributes (such as relative, absolute, etc.) to floating elements;
3. Remove floating.

2. In the second case

Under IE6, the performance of the hierarchy sometimes does not depend on the z-index of the sub-tag, but on the entire DOM tree ( The level of the parent tag of the first relative attribute of the node tree).

eg: IE7 and IE6 have the same bug. The reason is very simple. Although the current father level of the page where the picture is located is very high (1000), because the father's father is not useful, it is pitiful like 9999. Strong children have no future! , the code is as follows:

<p style="POSITION: relative">
<p style="POSITION: relative; Z-INDEX: 1000">
<p style="POSITION: absolute; Z-INDEX: 9999"> <IMG src="/131101/1A3194V7-1.jpg"> </p>
</p> 
</p>
Copy after login

Solution: Add a higher level (z-index: 1) to the first relative attribute, the code is as follows:

<p style="POSITION: relative; Z-INDEX: 1">  
<p style="POSITION: relative; Z-INDEX: 1000">  
<p style="POSITION: absolute; Z-INDEX: 9999"> <IMG src="/131101/1A3194V7-1.jpg"> </p>  
</p>  
</p>
Copy after login

The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About CSS3 Analysis of rem (set font size)

The above is the detailed content of How to solve the problem of invalid adjustment of z-index attribute of div layer. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Easy way: remove z-index attribute with jQuery Easy way: remove z-index attribute with jQuery Feb 23, 2024 pm 05:18 PM

Using jQuery to remove the z-index attribute is a very simple operation. The following will demonstrate how to achieve this operation through specific code examples. First, we need to introduce the jQuery library into HTML, you can use the following CDN link: &

Interpretation of CSS cascading properties: z-index and position Interpretation of CSS cascading properties: z-index and position Oct 20, 2023 pm 07:19 PM

Interpretation of CSS cascading properties: z-index and position In CSS, the design of layout and style is very important. In design, it is often necessary to layer and position elements. Two important CSS properties, z-index and position, can help us achieve these needs. This article will dive into these two properties and provide specific code examples. 1. z-index attribute The z-index attribute is used to define the stacking order of elements in the vertical direction. Stacking of elements

What does z-index mean in css? What does z-index mean in css? Nov 20, 2020 pm 02:21 PM

In CSS, z-index means "level, layer space stacking level". You can specify the stacking order of an element, which is used to confirm the stacking level of the element in the current stacking context. Elements with a higher stacking order will always be In front of elements lower in the stacking order; syntax "element {z-index:auto|<integer>}".

HTML layout tips: How to use the z-index attribute for cascading element control HTML layout tips: How to use the z-index attribute for cascading element control Oct 20, 2023 pm 05:50 PM

HTML layout skills: How to use the z-index attribute to control cascading elements Introduction: In HTML and CSS, layout is an important part of web design. When implementing web page layout, we often encounter situations where elements need to be displayed in a cascading manner, such as a navigation bar floating at the top, a pop-up window popping up above other content, etc. This article will introduce how to use the z-index property of CSS to implement cascading control of elements and provide specific code examples. 1. What is the z-index attribute z-in

HTML layout tips: How to use the z-index attribute to control the level of cascading elements HTML layout tips: How to use the z-index attribute to control the level of cascading elements Oct 18, 2023 am 09:09 AM

HTML layout skills: How to use the z-index attribute to control the level of cascading elements. In web design and development, we often need to control the level of elements to achieve the desired layout effect. At this time, the z-index attribute is our good helper. The z-index attribute can control the stacking order of elements in the vertical direction, allowing us to easily adjust the display priority of elements. Let us learn how to use the z-index attribute to control the level of cascading elements through specific code examples.

A deep dive into the z-index attribute and its common attribute values: Understanding absolute positioning A deep dive into the z-index attribute and its common attribute values: Understanding absolute positioning Dec 28, 2023 am 11:41 AM

Understand the common attribute values ​​​​of absolute positioning: In-depth analysis of the z-index attribute in CSS In CSS, absolute positioning (absolutepositioning) is a common positioning method used to accurately control the position of elements on the page. One of the important attribute values, z-index, can help us determine the overlapping order of elements in the vertical direction. In this article, we will analyze the z-index attribute in depth and give specific code examples to help readers better understand and use this

Use jQuery to remove the z-index value of an element Use jQuery to remove the z-index value of an element Feb 23, 2024 pm 09:06 PM

Using jQuery to remove the z-index attribute of an element is a common operation, especially when you need to dynamically adjust the stacking order of elements. By removing the z-index attribute of an element, you can restore the element to its default stacking order so that it is no longer affected by z-index. The following will use a specific code example to demonstrate how to use jQuery to remove the z-index attribute of an element:

Remove the z-index attribute of an element using jQuery Remove the z-index attribute of an element using jQuery Feb 19, 2024 pm 11:05 PM

When writing jQuery code, sometimes we need to remove the z-index value of an element. This may involve a variety of situations, such as dynamically modifying the element hierarchy, or setting the z-index to the default value under certain circumstances. In this article, we will introduce how to use jQuery to remove the z-index value of an element and give specific code examples. First, let’s understand what z-index does. The z-index attribute specifies an element in the stacking order

See all articles