margin 負值引起的層級(z-index)問題

來源:互聯網
上載者:User
這篇文章主要為大家介紹margin 負值引起的層級(z-index)問題的解決方案,需要的朋友可以參考下先來看這麼一段代碼:


複製代碼

代碼如下:


<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/">指令碼之家</a></p>
</p>


IE6和IE7下,內層的容器被外層覆蓋,:

在IE8和ff下,外層的容器被內層覆蓋,:

真是瘋狂啊,如果要達到IE8的外層的容器被內層覆蓋的效果,ie7可以通過觸發內層的layout解決,,但是IE6卻不行,只能在內層使用position:relative來解決問題,當然position:relative也解決ie7的問題,因為position:relative本身就能觸發layout。
看代碼:


複製代碼

代碼如下:


<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/">指令碼之家</a> </p>
</p>


當然要IE8、FF達到IE6、IE7的效果就只要在外層加overflow:hidden 就可以了,看代碼


複製代碼

代碼如下:


<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/">指令碼之家</a> </p>
</p>

相關文章

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.