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

前端之家收集整理的这篇文章主要介绍了(为什么)是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.

[大胆强调我]

猜你在找的CSS相关文章