


Solution to the level problem that relative absolute cannot break through_Experience exchange
if we set li to position: relative; set span to position: absolute; then we will find that no matter how high the z-index value of span is set, it will always be below the parent behind it.
some time ago, i remember who asked a question in the group that really made everyone confused:
1 2 3 4 5 6 7 |
|
if we set li to position:relative ;set span to position:absolute; then we will find that no matter how high the z-index value of span is set, it will always be below the parent behind it.
1 2 3 |
|
it is easy to find our children by trying it. the z-index value reaches 1000 and is set to position:absolut; the children are all filed under the parent. i thought about it for a long time, and i think the fundamental problem is: setting the same position: relative/absolute; the level between labels of the same level cannot be surpassed by z-index. in our example above, the level of the first li will always be smaller than the level of the next li, so we set position:absolute; on the children in li, giving a very high z-index value.
maybe you will think about it: as long as you set position: relative; very correct. when no other li sets position:relative; then the child we need can float above all content. but what if, in fact, span is required in all lis, and all properties need to be the same? of course we don't necessarily need this effect. but we need to have such an effect: all children are hidden, appear when there is a mouse reaction and float above all content. we need to know that this is indeed a headache, because as we saw above, the children are pressed under the next parent label when displayed. let's implement the positioning effect of this mouse response:
1 2 3 4 5 6 7 |
|
we complete this display-hide effect through the linked mouse event:
1 2 3 4 5 6 |
|
we set a to position:relative ;in this way, its children will be positioned based on the upper left corner of the parent as the coordinate origin. then we set the specific shape and positioning properties of the span, and then hide it. we then use a's pseudo-class:hover to activate span. if we look at the results, we'll see that everything that should be on top is now on the bottom. so how do we solve this problem? in fact, it is impossible to force a breakthrough with css, so we think about it, can we make the parent tag that has not been triggered not have the position:relative; attribute, but only when it is triggered? assign such a value to this parent? in fact, thinking of this can basically solve all the problems:
1 2 3 4 5 6 |
|
we only need to set the attribute of a:hover to position:relative;, so that a will be assigned a relative positioning attribute only when the mouse is triggered. this completes the problem of being blocked by other parent tags.
of course, if you don’t mind browsers like ie5, we can also simplify the code:
1 2 3 4 5 6 7 |
|
the css can be changed to this:
1 2 3 4 5 |
|
additional:
the article "position: relative/absolute cannot break through the level" published some time ago talked about the level in positioning. when i read it again in the past few days, i found that the article was not thorough and did not point to the key point. therefore, i would like to make a special supplement here in the hope that the levels in position can be explained more clearly and explicitly.
we all know that position has four different values, namely: static | absolute | fixed | relative. this is explained in su yu's "css2 chinese manual": static: no special positioning, the object follows html positioning rules; absolute: drag the object out of the document flow, use left, right, top, bottom and other attributes to make absolute position. and its cascading is defined through the z-index attribute. at this time, the object does not have margins, but there are still padding and borders; relative: the object cannot be stacked, but will be offset in the normal document flow based on attributes such as left, right, top, bottom, etc.; fixed: ie5.5 and ns6 are not yet available this property is not supported.
but to change the stacking position of an object, you need another css property: z-index. but this z-index is not omnipotent. it is restricted by the html code level. z-index can only reflect its effect on html of the same level. what needs to be stated here is that z-index can only be used when the position value of the object is relative/absolute. below we will give some examples to explain the characteristics of levels:
1 2 3 4 |
|
for the above html code, we also need to write a css to define it:
1 2 3 |
|
this is the most common in this case, the stacking level of #a and #b can be set through z-index. this is not asked, so under what circumstances will problems arise? let’s look at another example:
1 2 3 4 5 6 |
|
write another css based on this structure. pay attention to the different places in this css:
1 2 3 4 |
|
at this time we see, no matter #a is set to no matter how high the value is, it cannot exceed #b, so z-index cannot break through the level of html. it must be at the same level before it can exert its power. so how to solve this problem? i can think about it the other way around. , the order between cousins cannot be reorganized, why not reorganize the level of the parents? so we add a z-index: 100; to the css of #box_1 and z-index: 1; to the css of #box_2. let’s take a look at the effect again:
1 2 3 4 5 6 |
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.
