我有幾分相似的風格,每個都有約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