我使用Paul Irish的IE Conditional Comments技巧来定位不同版本的IE。在sass中,当嵌套在另一个类中时,如何应用其中一个类。
.container{
// I need to put a ie8 specific style here which is a .ie8 class applied to the body
}
我希望尽可能避免这样做(能够将这些属性保持在一起很好):
.container{}
.ie8{
.container{}
}
这可能吗?
答案 0 :(得分:1)
我有点不清楚你要特意做什么。但是如果你想做我认为你想做的事情,那么你可以使用一个变量。
例如,假设您只想在IE中将字体颜色设置为红色。你可以做这样的事情。虽然我没有看到使用SASS在这个用例中是多么有用,除非你当然试图做一些不同的事情。
<强> SASS:强> 您可以在以下位置对此进行测试: http://sassmeister.com/
$ieEightAndNine: "\0/";
.container {
color:unquote(red + $ieEightAndNine);
width:100px;
height:100px;
}
<强> CSS:强>
.container {
color: red\0/;
width: 100px;
height: 100px;
}
测试CHROME VS IE:
答案 1 :(得分:1)
我相信这就是你要找的东西 - 使用SASS's parent selector "&",你可以这样做:
.container {
.ie8 & {
// ie8 specific styles here
}
}