【发布时间】:2012-11-28 02:59:20
【问题描述】:
我有一个 .scss 文件,其中包含以下内容:
nav {
font-size: 0;
ul {
margin: $padding/3;
}
li {
z-index: 10;
position: relative;
display: inline-block;
font-size: $fontSize;
/**
* If we want separated, Uncomment!
margin: $padding/3;
@include border-radius(5px);
*/
&:first-child {
@include border-radius(0 5px 5px 0);
}
&:last-child {
@include border-radius(5px 0 0 5px);
}
padding: $padding/3 0;
@include background(linear-gradient(lighten($textColor, 10%), $textColor));
border: 1px solid lighten($textColor, 20%);
a {
color: $brightColor;
padding: $padding/3 $padding;
font-weight: bold;
text-decoration: none;
@include transition(.2s all);
}
//Nested menues
ul {
opacity: 0;
//display: none;
position: absolute;
margin: 0;
top: 0;
left: 0;
right: 0;
z-index: 5;
pointer-events: none;
@include transition(.2s all);
li {
@include background(linear-gradient(darken($brightColor, 10%), darken($brightColor, 30%)));
display: block;
border: 1px solid lighten($textColor, 20%);
&:first-child {
@include border-radius(0);
}
&:last-child {
@include border-radius(0 0 5px 5px);
}
a {
color: $textColor;
}
}
}
&:hover ul {
pointer-events: all;
top: 100%;
opacity: 1;
//display: block;
}
}
}
它在实践中有多糟糕/有害?我听过很多关于“不要超过 3 个嵌套选择器!”的讨论。但它真的有害吗?它对页面加载有任何明显的影响吗?我所做的基准测试说不,但我有什么遗漏吗?
【问题讨论】:
-
我最担心的是它们生成的 CSS 文件的大小,但我相信编译器知道如何缩小...
-
如果能真正收到关于这个问题的正确答案,我会非常棒。幕后是否有一些编译器优化?当特定的 SCSS 规则(选择器?)被翻译成可能性能不佳的东西时,是否有可能收到来自编译器的警告?
-
@ZenMaster - 我不知道警告,但我知道正在进行优化(尽管它可能是 Compass 的事情)。我见过许多将具有匹配属性的选择器组合在一起的情况(所以
p{color:red} div{color:red}变成了p, div{color:red})。
标签: css performance css-selectors sass