(拓展补充) 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