(为什么)是CSS星型选择器被认为有害? [英] (why) is the CSS star selector considered harmful?

查看:133
本文介绍了(为什么)是CSS星型选择器被认为有害?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



有没有使用它的注意事项?

  * {
margin:0;
padding:0;
}


解决方案

Steve Souders是人:





  • 简化CSS选择器

  • ul>

    无耻的报告来自其中一个报告:


    优化CSS选择器的关键是
    聚焦到最右边的选择器
    也称为键选择器
    (巧合?)。这里有一个更多的
    昂贵的选择器:A.class0007 * {}。
    虽然这个选择器可能看起来更简单,但是
    浏览器的配置更昂贵。因为浏览器
    从右向左移动
    ,它以
    开头,检查所有与
    键选择器*匹配的元素。这意味着
    浏览器必须尝试将此
    选择器与
    页面中的所有元素相匹配。


    [粗体强调我]


    does the star selector in CSS affect page rendering performance ?

    are there any caveats using it ?

    * {
      margin:0;
      padding:0;
    }
    

    解决方案

    When it comes to performance, Steve Souders is the man:

    Shameless quote from one of the reports:

    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.

    [bold emphasis mine]

    这篇关于(为什么)是CSS星型选择器被认为有害?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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