【发布时间】:2014-12-27 17:04:04
【问题描述】:
我正在使用 Twitter Bootstrap 3,我想制作可重用的样式类。下面的代码完全按照我想要的方式工作,但它是否符合 Bootstrap 使用的 SMACKS /OOCSS 命名约定?
注意 - 我使用 LESS 而不是纯 CSS,所以我将使用变量来处理重复的边框厚度等内容。
<div class="box box-red">
<div class="odd">
First content
</div>
<div class="even">
second content
</div>
<div class="odd">
third content
</div>
</div>
<div class="box box-green">
<div class="odd">
First content
</div>
<div class="even">
second content
</div>
<div class="odd">
third content
</div>
</div>
/* Box styles */
.box {
margin: 10px;
border-radius: 10px;
}
.box > .odd,
.box > .even {
padding: 10px;
}
.box > .odd:last-child,
.box > .even:last-child {
border-bottom: none;
}
/* Red box styles */
.box-red {
background: #ffcccc;
border: 1px solid #ff0000;
}
.box-red > .odd,
.box-red > .even {
border-bottom: 1px solid #ff0000;
}
.box-red > .even {
background: #ff4c4c;
}
/* Green box styles */
.box-green {
background: #BCED91;
border: 1px solid #3B5323;
}
.box-green > .odd,
.box-green > .even {
border-bottom: 1px solid #3B5323;
}
.box-green > .even {
background: #78AB46;
}
【问题讨论】:
-
:nth-child()不是备选方案吗? -
类似
.box-even和.box-odd(即以小部件名称为前缀)会更容易引导。 -
我不是说问题的质量,这非常有用,但我想最好放在codereview.stackexchange.com