How do browsers read and interpret CSS?

前端 未结 7 1198
粉色の甜心
粉色の甜心 2020-12-01 07:59

Two part question:

  1. Do browsers have a built-in CSS interpreter like they do for JavaScript?
  2. When exactly does a browser read the CSS and when does it
相关标签:
7条回答
  • 2020-12-01 08:41

    Browsers read CSS lines from right to left. That's what both Google as Mozilla say. Google says 'The engine evaluates each rule from right to left' on http://code.google.com/speed/page-speed/docs/rendering.html. Mozilla says 'The style system matches rules by starting with the key selector, then moving to the left' on https://developer.mozilla.org/en/Writing_Efficient_CSS

    Take for example this CSS line: '.item h4'. The browser first searches for the all the 'h4' tags on the page and then looks if the h4 tag has a parent with the class name 'item'. If it finds one, it applies the CSS rule.

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