Level (Z-index) problem caused by negative margin

Source: Internet
Author: User
This article mainly introduces the solution of the level (Z-index) problem caused by margin negative value, the friend who need can refer to the following code:


Copy Code

The code is as follows:


<p style= "height:100px;width:200px; Border:solid 1px black; ">
<p style= "background-color:red;margin-top: -5px" mce_style= "Background-color:red;margin-top: -5px" >
<a href= "http://www.jb51.net/" mce_href= "http://www.jb51.net/" > Scripting House </a></p>
</p>


Under IE6 and IE7, the inner container is covered by the outer layer:

Under IE8 and FF, the outer container is covered by the inner layer:

Really crazy Ah, if you want to reach the outer layer of the IE8 of the container is covered by the effect, IE7 can be triggered by the inner layer of layout solution, but IE6 but not, only in the inner layer using position:relative to solve the problem, of course position: Relative also solves the IE7 problem, because position:relative itself can trigger layout.
Look at the code:


Copy Code

The code is as follows:


<p style= "height:100px;width:200px; Border:solid 1px black; ">
<p style= "background-color:red;margin-top: -5px;position:relative" mce_style= "Background-color:red;margin-top: -5px;position:relative ">
<a href= "http://www.jb51.net/" mce_href= "http://www.jb51.net/" > Scripting House </a> </p>
</p>


Of course, to IE8, FF to achieve IE6, IE7 effect as long as the outer layer plus overflow:hidden can be, see the code


Copy Code

The code is as follows:


<p style= "height:100px;width:200px; border:solid 1px black; Overflow:hidden" >
<p style= "background-color:red;margin-top: -5px; mce_style=" background-color:red;margin-top: -5px; " >
<a href= "http://www.jb51.net/" mce_href= "http://www.jb51.net/" > Script home </a> </p>
</p

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.