SASS Replicating nested selector

爱⌒轻易说出口 提交于 2019-12-01 11:41:08

My answer is in SCSS - not SASS so you'll have to convert...

For browser targeting like this, I would recommend using mixins, and furthermore - @content within a @mixin to achieve your desired results. It also sets up a much more understandable set of rules with context.

For your specific example, it's as simple as moving your inline-block fix into a mixin instead of declaring only as a class.

@mixin ie7-inline-block {
    display: inline;
    zoom: 1;
} 

#my-ul li { 
    display: inline-block; 
    .ie-lt8 & {
        @include ie7-inline-block;
    }
}

Even better than that though, by using @content, you can always ensure that your style is prefixed with .ie-lt8 by making a mixin like so:

@mixin ie7 {
    .ie-lt8 & {
        @content;
    }
}

#my-ul li {
    display: inline-block;
    @include ie7 {
        display: inline;
        zoom: 1;
    }
}

Which will output the same css, but allows your IE7-Specific styles to be wrapped each time in some context that makes sense to anyone who reads your code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!