(拓展补充) CSS书写顺
衡量程序员的能力,除了要看实现业务需求的能力,还要看平时书写代码的规范(专业性)
不同的CSS书写顺序会影响浏览器的渲染性能,推荐前端工程师使用专业的书写顺序习惯
| 顺序 | 类别 | 属性 |
|---|---|---|
| 1 | 布局类型 | display、position、float、clear、visibility、overflow |
| 2 | 盒子模型+背景 | width、height、margin、padding、border、background |
| 3 | 文本内容属性 | color、font、text-decoration、text-align、line-height |
| 4 | 点缀属性 | cursor、border-radius、text-shadow |
基础CSS
/* index.css 用来美化首页 */
* {
margin: 0;
padding: 0;
/* 內减模式 */
box-sizing: border-box;
}
/* li标签取消前面的小点 */
li {
list-style: none;
}
/* a标签取消下划线 */
a {
text-decoration: none;
}
/* 清除浮动 */
.clearfix:before,.clearfix:after {
content:"";
display:table;
}
.clearfix:after {
clear:both;
}
body{
background-color: #f3f5f7;
}
/* 版心 */
.wrapper{
width: 1200px;
margin: 0 auto;
}
注意点:
• 开发中推荐多用类 + 后代,但不是层级越多越好,一个选择器中的类选择器的个数推荐 不要超过 3
本文强调了CSS代码规范对于程序员能力评估的重要性,指出合理的CSS书写顺序可以影响浏览器渲染性能。推荐的顺序包括:布局类型、盒子模型+背景、文本内容属性和点缀属性。示例代码中展示了基础的CSS清理和设置,如通用样式、li和a标签的处理,以及版心的定义。开发中应注意选择器的简洁性,避免过多的类选择器。
452

被折叠的 条评论
为什么被折叠?



