多次声明相同的CSS类 [英] Declaring same CSS class multiple time

查看:92
本文介绍了多次声明相同的CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆