文章详情页
css3 - 使用自定义属性来写 CSS 选择器是否更优雅?
问题描述
小伙伴推荐在 css 中使用自定义属性代替 class 做选择器,
html:
<button bg='blue'>blue</button><button bg='red'>red</button>
css:
[bg='blue'] { background-color: blue;}[bg='red'] { background-color: red;}
http://codepen.io/Integ/pen/YPRpWE
相比用 class 和 tagname 做选择器,每个属性控制一个样式更加清晰明了,避免了选择器中 class 对权重的影响。
但是自定义属性增加了html的复杂度。
前端应该如何合理使用属性选择器?
问题解答
回答1:好吧,性能成指数下降。
干嘛不这样写?
css.bg-blue { background: blue;}
html<p class='bg-blue'></p>
标签:
CSS
相关文章:
1. python相关问题求解决,有偿2. javascript - input输入框触发change事件后,外部元素会被选中3. python - 用__call__ 实现装饰器功能4. javascript - vue2.0中router.repalce跟router.push有什么区别,二者的应用场景是会有怎样的区别?5. javascript - prismplayer播放器全屏问题6. javascript - 在sublime中如何给.vue文件注释?7. python - 请问用cxfreeze打包的可执行程序能反编译出源码么?8. HTML5怎么访问本地文件?9. javascript - 这种上传图片预览怎么做?10. javascript - 把字符串日期转换成一般时间格式后,发现小于10的数字不会自动添加0在前面,如下
排行榜