【发布时间】:2011-06-08 11:14:21
【问题描述】:
可能重复:
Should css class names like 'floatleft' that directly describe the attached style be avoided?
我想知道 CSS 类的命名和使用的最佳做法是什么。
例如,在您希望将按钮文本和标题文本的文本居中的情况下,最好在两个类中重复这种样式,例如
.button-text {
text-align: center;
/*some properties*/
}
.header-text {
text-align: center;
/*other properties*/
}
或者将这种样式移到一个单独的类中是更好的做法,例如
.center {
text-align: center;
}
.button-text {
/*some properties*/
}
.header-text {
/*other properties*/
}
并将“center”类应用于具有“button-text”和“header-text”类的元素。
归根结底,CSS 类名应该代表元素是“按钮文本”还是“状态”,元素看起来像“中心”?
谢谢!
【问题讨论】:
标签: css