将:before和:after clearfix更新为简单的::after是否安全



目前,我使用的一个框架使用了经典的clearfix:

@mixin clearfix {
    zoom: 1;
    &::before,
    &::after {
        content: '';
        display: table;
    }
    &::after {
        clear: both;
    }
}

我想知道,既然IE7不再受支持,那么放弃使用::before是否安全,这样我就可以清除一个可能也需要伪元素用于装饰目的的元素。我的建议是将其转化为以下内容:

@mixin clearfix {
    &::after {
        clear: both;
        content: '';
        display: table;
    }
}

据我所知,这将和::before一样有效,但我想在做出更改之前绝对确定,因为如果我弄错了,这将影响数十万用户,我不想成为那个人。

提前感谢!

我决定修改mixin,以便在提示时使用简单版本,否则允许它默认为当前版本。

我还注意到IE8也不受支持,因为假名使用了双冒号,所以我在那里的时候也解决了这个问题。。。

@mixin clear-fix($simple: false) {
    @if $simple != true {
        zoom: 1;
        &:before,
        &:after {
            content: '';
            display: table;
        }
        &:after {
            clear: both;
        }
    }
    @else {
        &::after {
            clear: both;
            content: '';
            display: table;
        }
    }
}

用法:

@include clear-fix; // prints out old-skool :before/:after with IE7/8 support

@include clear-fix(true); // prints out simple ::after method

最新更新