& #183; DIV CSS3 processes overlapping elements, and divcss3 elements overlap

Source: Internet
Author: User

· 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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.