css规范的codereview_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了css规范的codereview_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4785字,纯文字阅读大概需要7分钟。
内容图文
![css规范的codereview_html/css_WEB-ITnose](/upload/InfoBanner/zyjiaocheng/406/ce0cb56539c147ce95d69eed65d78690.jpg)
引入了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;}
内容总结
以上是互联网集市为您收集整理的css规范的codereview_html/css_WEB-ITnose全部内容,希望文章能够帮你解决css规范的codereview_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。