多次声明相同的CSS类 [英] Declaring same CSS class multiple time
问题描述
<div class="big_box">haha</div>
<div class="small_box">haha</div>
这(类型1)似乎可行: -
This (type 1) seems workable :-
.big_box, .small_box { border:1px solid #ccc; /* lengthy attributes*/}
.big_box { width:150px; height:150px; }
.small_box { height:140px; width:140px; }
这(类型2)也可以工作: -
This (type 2) also works :-
.big_box { border:1px solid #ccc; width:150px; height:150px; /* same lengthy attributes*/}
.small_box { border:1px solid #ccc; width:150px; height:150px; /* same lengthy attributes* }
当然,类型2是冗长的,属性(具有相同的值),
使用类型1时是否有任何问题?
(或只是允许?)
Of course, type 2 is lengthy and repeating for most of the common attributes (with same value),
is there any issue for using type 1 ?
(or simply this is allowed ?)
PS type 3也适用(但我发现很难管理)... if
P.S type 3 works too (but I find is hard to manage) ... if
<div class="box big">haha</div>
和
.box { border:1px solid #ccc; /* lengthy attributes*/}
.big { width:150px; height:150px;}
推荐答案
type 1实际上很常见当声明多个类时,一些共享相同的属性,一些具有它们拥有的唯一属性。类型2是有点脏,维护类型3类似于类型1.
type 1 is actually very common when declaring multiple classes with some share the same attributes and some have their owned unique attributes. type 2 is a bit dirty to maintain while type 3 is similar to type 1.
这是所有的工作,只是一个编码风格和易于维护的问题
it is all works, just a matter of coding style and ease of maintenance
这篇关于多次声明相同的CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!