· DIV CSS3 processes overlapping elements and divcss3 overlapping elements
Using the top and left attributes may cause overlapping elements. You can use the z-index attribute. The z-index attribute is used to control the display sequence of overlapping elements. Elements with higher values overwrite those with lower values. If the value is-1, it indicates that the element will be behind the default text of the page, which is useful for setting the background pattern. If you think of the computer screen as a X-Y plane, then the Z axis is perpendicular to the screen. Note that the z-index attribute is valid when the position is set and the value is "absolute" or "relative.
In the following code, three div elements are used, and the position attribute of the three div elements is set to absolute. The offset position and z-index values are different.
① Case HTML code:
<! DOCTYPEHtml>
<Html>
<HeadLang ="En">
<MetaCharset =UTF-8">
<Title> </Title>
<LinkRel ="Stylesheet"Href ="Test.css"/>
</Head>
<Body>
<DivId ="Box">
<DivId ="Top">
<ImgSrc ="Top. Jpg"Alt ="Top"/>
</Div>
<DivId ="Middle">
<ImgSrc ="Middle. Jpg"Alt ="Middle"/>
</Div>
<DivId ="Bottom">
<ImgSrc ="Bottom. Jpg"Alt ="Bottom"/>
</Div>
</Div>
</Body>
</Html>
① Case CSS code:
# Box{
Width500Px;
Height600Px;
Border: 3Px dashed#000;
}
# Top{
Position:Absolute;
Left170Px;Top170Px;
Z-index: 3;
}
# Middle{
Position:Absolute;
Left100Px;Top100Px;
Z-index: 2;
}
# Bottom{
Position:Absolute;
Left: 40Px;Top: 40Px;
Z-index: 1;
}
Effect: