我想知道何时以及如何对重复的属性进行分类。考虑结构之间的可读性、代码性能、缺点和优点。假设我有两个CSS代码:
第一法典:
.a {
text-align: center;
font-size: 1em;
background-color: red;
}
.b {
text-align: center;
font-size: 1em;
background-color: green;
}
.c {
text-align: center;
font-size: 2em;
background-color: blue;
}
.d {
background-color: blue;
}第二法典:
.a,
.b,
.c {
text-align: center;
}
.a,
.b {
font-size: 1em;
}
.c,
.d {
background-color: blue;
}
.a {
background-color: red;
}
.a {
background-color: green;
}
.c {
font-size: 2em;
}那么哪一个是更好的人,非常感谢之前:)
发布于 2015-10-12 11:42:36
关于可读性和结构,我认为这取决于应用程序的复杂性和组织性。
为了组织您的CSS代码,常见的实践是这样的,当您在大型应用程序中工作并且涉及到几个开发人员时,这一点特别有用。
边界元
块、元素、修饰符-是一种命名方法。这是一种聪明的方法来命名您的类,赋予更多的意义和可读性。
更多信息在这里:
https://css-tricks.com/bem-101/
http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
SMACSS
表示CSS的可扩展和模块化体系结构,它更像是CSS的样式指南。
更多信息在这里:
https://stackoverflow.com/questions/33079489
复制相似问题