How do browsers read and interpret CSS?

前端 未结 7 1219
粉色の甜心
粉色の甜心 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:40

    I recently bumped into this article on google page speed:

    As the browser parses HTML, it constructs an internal document tree representing all the elements to be displayed. It then matches elements to styles specified in various stylesheets, according to the standard CSS cascade, inheritance, and ordering rules. In Mozilla's implementation (and probably others as well), for each element, the CSS engine searches through style rules to find a match. The engine evaluates each rule from right to left, starting from the rightmost selector (called the "key") and moving through each selector until it finds a match or discards the rule. (The "selector" is the document element to which the rule should apply.)

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

提交回复
热议问题