css编写规范:如何合并组合类和嵌套类

css控制网页布局,当网页逐步扩展后,会发现css越来越混乱,只能怪刚开始写的时候没有计划好,所以只能二次重构。

css重构1:合并具有相同的属性的选择器
原内容:
h2 {
color: red;
}
.thisOtherClass {
color: red;
}
.yetAnotherClass {
color: red;
}

重构后:
h2, .thisOtherClass, .yetAnotherClass {
color: red;
}


css重构2:嵌套
网页结构如下:
<div id="top">
<h1>Chocolate curry</h1>
<p>This is my recipe for making curry purely with chocolate</p>
<p>Mmm mm mmmmm</p>
</div>
嵌套css如下:
#top {
background-color: #ccc;
padding: 1em
}
#top h1 {
color: #ff0;
}
#top p {
color: red;
font-weight: bold;
}

原文出处:广漠传播 上海网站建设(http://www.greatmo.com/post/101.html)