【发布时间】:2018-04-28 00:30:36
【问题描述】:
我看到人们为每个对象创建类,例如:
.content-wrapper {
display: flex;
justify-content: center;
color: white;
}
.images-wrapper {
display: flex;
justify-content: center;
border: 1px solid white;
}
<div class="content-wrapper"></div>
<div class="images-wrapper"></div>
而且,我看到人们通过属性创建类,例如在 Bootstrap 中:
.centered-content {
display: flex;
justify-content: center;
}
.content-wrapper {
color: blue;
}
.images-wrapper {
border: 2px solid black;
}
<div class="centered-content content-wrapper"></div>
<div class="centered-content images-wrapper"></div>
【问题讨论】:
-
第一个应该是ID,而不是类。
-
这确实是一个开放性问题,可以辩论,有些人提出了命名约定/解决方案,例如 BEM、SMACSS,我认为这是一个很好的讲座getbem.com/introduction
-
@NiettheDarkAbsol ID 的唯一问题是你可能会因为特殊性问题而让你的生活更加困难。
-
任何类的命名都不应与它所分类的内容无关。由于您不提供任何内容,因此任何类命名策略都无效。
标签: html css code-organization