CSS中的更好:div.something或只是.something

编程入门 行业动态 更新时间:2024-10-22 13:56:23
本文介绍了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

本文发布于:2023-10-13 09:57:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CSS   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!