微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

(为什么)是CSS星型选择器被认为有害?

CSS中的星型选择器会影响页面呈现性能吗?

有什么警告使用它吗?

* {
  margin:0;
  padding:0;
}

解决方法

当谈到性能,史蒂夫·苏德斯是男人:

> Performance Impact of CSS Selectors
> Simplifying CSS Selectors

无耻的报价从其中一个报告:

The key to optimizing CSS selectors is
to focus on the rightmost selector,
also called the key selector
(coincidence?). Here’s a much more
expensive selector: A.class0007 * {}.
Although this selector might look
simpler,it’s more expensive for the
browser to match. Because the browser
moves right to left
,it starts by
checking all the elements that match
the key selector,“*“. This means the
browser must try to match this
selector against all elements in the
page.

[大胆强调我]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。