【发布时间】:2014-04-21 16:33:14
【问题描述】:
我刚想按如下方式组织我的工作:
创建非常基本的 CSS 类,例如:
.backgroundRed {
background-color:red;
}
.backgroundGreen {
background-color:green;
}
.fixed300 {
width:300px;
}
.percent100 {
width: 100%;
}
.centered {
margin: auto;
}
.centeredTextHorizontally {
text-align:center;
}
.colorWhite {
color:white;
}
然后同时使用其中的 2-3-4 个,来创建我想要的,例如:
<div class = "backgroundGreen fixed300 centered">
<div class="centeredTextHorizontally">300px wide green stripe with centered text</div>
<div class="centeredTextHorizontally colorWhite">Centered white text</div>
</div>
</div>
我相信你明白了。
现在的问题是,如果将来我们想更改网站,我们需要编辑所有这些 DIV 的 HTML,这首先打破了使用 CSS 的初衷。
所以我希望能够如下定义 CSS 类
.navbar {
.colorRed;
.backgroundColorGreen;
}
etc 等等。例如,如果需要更改网站颜色,我只更改 .navbar 而不是 HTML 中的 DIV。
是否可以执行上述操作以及如何执行?
【问题讨论】: