简体   繁体   English

绝对定位元素在IE7上被裁剪

[英]Absolute positioned element gets cropped on IE7

So it has veen a long time since a client has asked me to support IE7 and now I'm suffering the consequences. 因此,自从客户要求我支持IE7以来,已经有很长时间了,而现在我正承受着后果。 I have 4 divs with an icon (the red square in the example) in between them: 我有4个div,它们之间有一个图标(示例中的红色方块):

<div class="slider-wrapper">
    <div class="tabs">                                                                  
        <div class="item-1 total-4">
            <span>Cumulez les avantages !</span> 
            <div class="icons small icons-plus"></div>                              
        </div>                                             
        <div class="item-2 total-4">
            <span>Avantages Installateurs</span>  
            <div class="icons small icons-plus"></div>                              
        </div>                                                
        <div class="item-3 total-4">
            <span>Avantages Fabricants</span>   
            <div class="icons small icons-plus"></div>                           
        </div>                                              
        <div class="item-4 total-4">
            <span>Prime économies d’énergie</span>                    
        </div>
    </div>                                    
</div>

The icons must be between each of the divs and it works in every major browser including IE8, but on IE7 it gets cropped, ignoring the z-index I give it. 图标必须位于每个div之间,并且可以在包括IE8在内的每个主要浏览器中使用,但在IE7上,它会被裁剪,而忽略了我给它的z索引。

This is a jsfiddle I made with the example: 这是我用示例制作的jsfiddle:

http://jsfiddle.net/z2K66/ http://jsfiddle.net/z2K66/

You can test it on IE7 using this url: http://jsfiddle.net/z2K66/embedded/result/ and you will see how the red squares are cut in half. 您可以使用以下URL在IE7上对其进行测试: http : //jsfiddle.net/z2K66/embedded/result/ ,您将看到红色方块如何被切成两半。 If you use the regular fiddle it will break cause they don't support IE7 (lucky them!) 如果您使用常规小提琴,它将损坏,因为它们不支持IE7(幸运的是!)

This is my css: 这是我的CSS:

.slider-wrapper .tabs .total-4 {
    background-color: #8F1083;
    color: #FFFFFF;
    display: table;
    float: left;
    font-size: 17px;
    font-weight: bold;
    height: 75px;
    position: relative;
    text-align: center;
    width: 25%;
}

.slider-wrapper .tabs span {
    display: table-cell;
    vertical-align: middle;
}
.slider-wrapper .tabs .icons {
    position: absolute;
    right: -15px;
    top: 24px;
    height:30px;
    width:30px;
    background:red;
    z-index: 111111111;
}

Fixing IE z-index. 修复IE z-index。 Credit goes to CSS Tips 归功于CSS技巧

This isn't a complete solution to fix all weird IE z-index issues. 这不是解决所有奇怪的IE z-index问题的完整解决方案。 What it does is loop through each of the elements that you declare and apply ever-declining z-index values on them. 它的作用是循环遍历您声明的每个元素,并对它们应用不断下降的z-index值。 IE gets this backwards, and this sets it correctly. IE将此倒退,并正确设置了它。 The reason it's not the complete solution is because sometimes it's not DOM-order that you need z-index to be in, and sometimes scoping comes into play as well. 之所以不是完整的解决方案,是因为有时您需要z-index并不是DOM顺序的,有时作用域也起作用。

Nonetheless, the view the demo in IE 7. 尽管如此,请查看 IE 7中的演示

JQuery Version jQuery版本

$(function() {
   var zIndexNumber = 1000;
   // Put your target element(s) in the selector below!
   $("div").each(function() {
           $(this).css('zIndex', zIndexNumber);
           zIndexNumber -= 10;
   });});

MooTools Version MooTools版本

if(Browser.Engine.trident){
   var zIndexNumber = 1000;
   // Put your target element(s) in the selector below!
   $$('div').each(function(el,i){
           el.setStyle('z-index',zIndexNumber);
           zIndexNumber -= 10;
   });};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM