請幫助我確定哪種方法更好(html標記中有2個類或具有相同屬性的2個類),爲什麼?哪種方法更好: - 在html標記中有2個類或者具有相同屬性的2個類
方法1種
<html><body>
<p class="redColor buttonHeight"> button Red</p>
<p class="blueColor buttonHeight"> button Blue</p>
</body></html>
.redColor{color:red}
.blueColor{color:blue}
.buttonHeight{height:10px}
方法2
<html><body>
<p class="redColorHeight"> button Red</p>
<p class="blueColorHeight"> button Blue</p>
</body></html>
.redColorHeight{color:red}
.blueColorHeight{color:blue}
.redColorHeight,.blueColorHeight{height:10px;}
感謝itay,這些只是假設的類名,我的實際問題是關於css屬性的實現。爲什麼方法1比方法2更好,反之亦然 –
如果你給你的班級有意義的名字,它會幫助你做出決定。如果每個班級分別有意義,最好將他們分開。如果沒有,那麼第二種方法是可以的。 – Itay
@New_To_Android我建議你在你的問題中重構樣本,以便與此答案類似。它會幫助我們迴應:-) – promanski