1模块化
- 每个模块必须是一个独立的样式文件,文件名与模块名一致;
- 模块样式的选择器必须以模块名开头以作范围约定;
假定有一个模块如前文 HTML模块化,那么 m-detail.scss 的写法大致如下:
.m-detail {background: #fff;color: #333;&-hd {padding: 5px 10px;background: #eee;.title {background: #eee;}}&-bd {padding: 10px;.info {font-size: 14px;text-indent: 2em;}}&-ft {text-align: center;.more {color: blue;}}}
编译之后代码如下:
.m-detail {background: #fff;color: #333;}.m-detail-hd {padding: 5px 10px;background: #eee;}.m-detail-hd .title {background: #eee;}.m-detail-bd {padding: 10px;}.m-detail-bd .info {font-size: 14px;text-indent: 2em;}.m-detail-ft {text-align: center;}.m-detail-ft .more {color: blue;}
任何超过3级的选择器,需要思考是否必要,是否有无歧义的,能唯一命中的更简短的写法
