文章详情页
css3 - 使用自定义属性来写 CSS 选择器是否更优雅?
浏览:159日期:2023-08-02 13:56:15
问题描述
小伙伴推荐在 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. 问题Unknown column ’’ in ’where clause’2. angular.js - 如何控制ngrepeat输出的个数3. html - vue项目中用到了elementUI问题4. javascript - 在使用 vue.js element ui的时候 怎么样保留table翻页后check的值?5. mysql_replication - mysql读写分离时如果单台写库也无法满足性能怎么解决6. javascript - vue组件通过eventBus通信时,报错a.$on is not a function7. css3 - css怎么实现图片环绕的效果8. linux - ubuntu 命令行中文 显示菱形,期望通过引入字体解决而不是zhcon这种方式9. ionic 项目 ionic build android -release 打包时报错10. python - 如何用pandas处理分钟数据变成小时线?
排行榜

网公网安备