我有几分相似的风格,每个都有约6-7行代码是一样的,就像这样:[class * =“custom-style-”]和“.this-class-is-default-style”之间更贵吗?
custom-style-1 {
font-size: 12px;
color: red;
//Here come the specifics!
}
custom-style-2 {
font-size: 12px;
color: red;
//Here come the specifics!
}
custom-style-3 {
font-size: 12px;
color: red;
//Here come the specifics!
}
..
..
所以我写了这一点,除了各阶级的重复属性:
[class*="custom-style-"],
[class*="custom-style-"] {
font-size: 12px;
color: red;
}
但后来想,为什么不只是写另一个类:
.this-class-is-default-style {
font-size: 12px;
color: red;
}
,只是将它添加到<div class="{list-here}">
在HTML中。
哪一个在渲染时间方面更昂贵?另外,使用方法是否存在灵活性问题或缺点,而不是唯一的方法?
_“哪一个在渲染时间方面更昂贵?” - 只有一些带有小卡钳和测量设备的怪胎才会知道...对于其他人来说,这将不重要:) – CBroe
@CBroe I'我非常努力地优化eveything,尽我所能从一开始就学会以某种方式编写代码,JS也是,所以我感兴趣:)也许有人知道答案。 –
你的实现也不完全正确。你有两次'[class * ='custom-style - “]''。其中一个应该是'[class^='custom-style - “]'而另一个应该是'[class * ='custom-style - ”]''。请参阅https://stackoverflow.com/questions/3338680/is-there-a-css-selector-by-class-prefix/8588532#8588532 – BoltClock