In which order are CSS styles applied?

前端 未结 3 1119
长发绾君心
长发绾君心 2020-12-09 16:36

I have the following HTML.


In my CSS stylesheet I have gener

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 16:52

    Here's an article about CSS Selector specificity which looks good: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/

    The section in How to measure specificity? gives you the answer:

    a:link   => one tag (a) + one pseudo-class (:link) = 1 + 10    = 11 points
    ul li a: => three tags (ul, li, a)                 = 1 + 1 + 1 =  3 points
    

    So the a:link style wins.

    Hint: Order (in the CSS files) only matters when two css selectors have the same specificity.

提交回复
热议问题