CSS中的更好:div.something或只是.something [英] What's better in CSS: div.something or just .something

查看:139
本文介绍了CSS中的更好:div.something或只是.something的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CSS中,在div(例如)上设置样式时,除了为匹配提供更高的精度之外,还包括div。浏览器是否可以更快地呈现?

In CSS, when setting a style on a div (for example) is there any benefit in including the 'div' other than to give it more precision for matching. Is it faster for the browser to render perhaps?

即是:

div.something { font-size: 1em; }

优于

.something { font-size: 1em; }

因为任何其他原因,而不是缩小到只有divs?

for any other reason than to narrow it down to only divs?

(我要求的原因是我最近碰到了一个突出的网站,其中包含了'div,但最不倾向)

更新:

感谢所有的答案。结论是,速度是一个因素,但不明显这么值得忽略。对最佳实践的共识是,包含标签是更清洁的 - 一般规则应该保持CSS尽可能紧尽可能为所需的风格。

Thanks for all the answers. The conclusion is that speed is a factor but not noticeable so worth ignoring. And the consensus on the best practice is that including the tag is cleaner - general rule should be to keep the CSS as 'tight' as possible for the required style.

推荐答案

除了两个选择器的不同语义外,请阅读: CSS的速度

Besides the different semantics of both selectors, read this: Speed of CSS

这篇关于CSS中的更好:div.something或只是.something的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆