Home >Web Front-end >HTML Tutorial >css 规范的 code review_html/css_WEB-ITnose

css 规范的 code review_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:14:581045browse

上个星期,制定的前端开发规范,今天抽查了css规范的执行;发现了很多问题

引入了css 模块化思想,可以接受少量的代码冗余,但不表示可以接受大面积的代码冗余。

表现症状1

.footer .home-icon:before{background-position:1px -166px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .productList-icon:before{background-position:-45px -166px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .me-icon:before{background-position:-89px -166px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .mores-icon:before{background-position:-135px -166px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .homeActive:before{background-position:1px -210px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .productListActive:before{background-position:-45px -210px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .meActive:before{background-position:-89px -210px;width: 42px;height: 40px;margin: 8px 0 2px}.footer .moresActive:before{background-position:-135px -210px;width: 42px;height: 40px;margin: 8px 0 2px}

上面的代码就范了大面积冗余的问题;

42px;height: 40px;margin: 8px 0 2px 这些代码都是一样的,完全可以把它们定义成一个。

.footer .icons:before{width: 42px;height: 40px;margin: 8px 0 2px}.footer .home-icon:before{background-position:1px -166px}.footer .productList-icon:before{background-position:-45px -166px}.footer .me-icon:before{background-position:-89px -166px}.footer .mores-icon:before{background-position:-135px -166px}.footer .homeActive:before{background-position:1px -210px}.footer .productListActive:before{background-position:-45px -210px}.footer .meActive:before{background-position:-89px -210px}.footer .moresActive:before{background-position:-135px -210px}

表现症状2

.property .regular-module1 .append-list{width: 100%;height: 90px;background-color: #FFF;}.property .regular-module1 .append-list .append-listData{display: inline-block;width: 88%;height: 90px}.property .regular-module1 .append-list .append-listData .append-word1{font-size: 24px;color: #666;padding-top: 18px;clear: both}.property .regular-module1 .append-list .append-listData .append-word2{font-size: 20px;color: #999;padding-top: 10px;clear: both}.property .regular-module1 .append-list .append-listData .append-wordData1{float: left;padding-left: 30px;}.property .integralDetails-module1 .append-list{width: 100%;height: 90px;background-color: #FFF;}.property .integralDetails-module1 .append-list .append-listData{display: inline-block;width: 100%;height: 90px}.property .integralDetails-module1 .append-list .append-listData .append-word1{font-size: 24px;color: #666;padding-top: 18px;clear: both}.property .integralDetails-module1 .append-list .append-listData .append-word2{font-size: 20px;color: #999;padding-top: 10px;clear: both}.property .integralDetails-module1 .append-list .append-listData .append-wordData1{float: left;padding-left: 30px;}

上列中,虽然分了模块,但事实上引入了3层的模块嵌套,我们完全没有必要这样做,完全可以简化成下面的内容,不仅css文件减少了,而且代码也更简洁;如果有差异,在增加一个样式嵌套就可以了,所以,一般只要3层嵌套就可以解决大部分的样式问题,模块实在太大,css太多,完全可以分拆成2个模块来实现。

.property .append-list{width: 100%;height: 90px;background-color: #FFF;}.property .append-listData{display: inline-block;width: 88%;height: 90px}.property .append-word1{font-size: 24px;color: #666;padding-top: 18px;clear: both}.property .append-word2{font-size: 20px;color: #999;padding-top: 10px;clear: both}.property .append-word-data1{float: left;padding-left: 30px;}

有些规范被忽略了

超过3层嵌套

.property .regular-module1 .append-list .append-listData{display: inline-block;width: 88%;height: 90px}.property .regular-module1 .append-list .append-listData .append-word1{font-size: 24px;color: #666;padding-top: 18px;clear: both}.property .regular-module1 .append-list .append-listData .append-word2{font-size: 20px;color: #999;padding-top: 10px;clear: both}.property .regular-module1 .append-list .append-listData .append-wordData1{float: left;padding-left: 30px;}.property .regular-module1 .append-list .append-listData .append-wordData2{float: right}.property .regular-module1 .append-list .append-listData .append-wordData3{color: #ff6046}.property .regular-module1 .append-list .append-listIcon{display: inline-block;margin-bottom: 32px}

规范定义css嵌套尽量在3层以内,上列尽量有5层嵌套,并且还有一个问题是,样式的命名采用了部分驼峰方式。

没有使用-线连接

使用了单词命名css

.more{float: right;margin: 0 20px;}.more:before{background-position:-116px 3px;width: 30px;height: 30px;margin-bottom: -7px}.eye,.eyes{float: right;display: inline-block;margin: 0 30px;}.eye:before{background-position:-240px 14px;width: 32px;height: 24px;}.eyes:before{background-position:-240px -12px;width: 32px;height: 24px;}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn