Why don't CSS resets use '*' to cover all elements?

前端 未结 3 941
一个人的身影
一个人的身影 2020-11-30 12:44

For example, the Meyer reset has a long list of elements1 which I believe can be replaced with a *?

I have seen some use of:

         


        
相关标签:
3条回答
  • 2020-11-30 13:14

    Mainly because its a performance hit. Also, since you do not want to apply reset to all elements all the time but the ones known to cause issues (around box model).

    Also, resetting style of select, input may cause undesirable experience.

    0 讨论(0)
  • 2020-11-30 13:19

    You've guessed correctly - the reason is form elements.

    If you set border: 0 on for example an input, it will lose the native styling.

    For example: http://jsfiddle.net/nrB6N/

    And, there's no way to get that default styling back.

    0 讨论(0)
  • 2020-11-30 13:29

    * is really, REALLY bad for performance (doesn't really matter on small sites, but think the repercussions for 5000+ HTML elements for example). Targetting specific elements is always faster and more efficient. It's a thing to also keep in mind when choosing wether to use an ID or an CLASS. Count in the more than common JavaScript today, and you find out that targetting elements with ID's or precise CSS statements yields in performance improvements.

    http://code.google.com/speed/page-speed/docs/rendering.html#UseEfficientCSSSelectors

    ps. Apart from speed, it also affects input elements, which after the * border, padding, and margin 0 become quite difficult to style so that they look the same accross browsers, especially in IE. Read more: http://www.christianmontoya.com/2007/02/01/css-techniques-i-use-all-the-time/

    0 讨论(0)
提交回复
热议问题