javascript - 为什么渲染树不包含绝对定位的元素?

标签 javascript html css google-chrome browser

我正在阅读有关渲染树的内容:

While the DOM tree is being constructed, the browser constructs another tree, the render tree. This tree is of visual elements in the order in which they will be displayed. It is the visual representation of the document. Render tree does not contain display:none, position absolute elements, HEAD.

最后一句话让我有点困惑。渲染树包含可见元素。因此,它应该包含绝对位置。浏览器如何渲染这些元素(display:none、位置绝对元素、HEAD)?谁能详细解释一下吗?

http://taligarsiel.com/Projects/howbrowserswork1.htm

最佳答案

我不确定您在哪里阅读该信息,但 position:absolute 元素(显然)已呈现。

有两棵树:DOM 和 CSSOM。两者结合起来生成构建我们所看到的页面的渲染树。

根据 Google 开发人员的说法,display: none 将不会呈现。但没有迹象表明 position:absolute 也不会渲染。

Google Developers - Render-tree construction, layout, and paint

A few salient points from the article:

  • The CSSOM and DOM trees are combined into a render tree, which is then used to compute the layout of each visible element and serves as an input to the paint process which renders the pixels to screen. (emphasis mine)

  • The DOM and CSSOM trees are combined to form the render tree. Render tree contains only the nodes required to render the page.

  • The first step is for the browser to combine the DOM and CSSOM into a “render tree” that captures all the visible DOM content on the page, plus all the CSSOM style information for each node. (emphasis mine)

  • To construct the render tree, the browser roughly does the following:

    • Starting at the root of the DOM tree, traverse each visible node.

      • Some nodes are not visible at all (e.g. script tags, meta tags, and so on), and are omitted since they are not reflected in the rendered output.

      • Some nodes are hidden via CSS and are also omitted from the render tree - e.g. the span node in example above is missing from the render tree because we have an explicit rule that sets display: none property on it.

    • For each visible node find the appropriate matching CSSOM rules and apply them.

    • Emit visible nodes with content and their computed styles.

  • The final output is a render that contains both the content and the style information of all the visible content on the screen. (emphasis mine)

在此处阅读全文:Render-tree construction, layout, and paint

关于javascript - 为什么渲染树不包含绝对定位的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34297091/

相关文章:

html - 有没有办法在没有 CSS Flex 的情况下从上到下或从左到右显示 HTML 列表?

html - 圆形容器的悬停效果

javascript - 如何在 AngularJS Emit 中将函数作为参数传递?

javascript - 从周围的 HTML 调用 SVG 内部的 JavaScript 函数

javascript 函数未定义错误。句法?

html - ie 的CSS 问题?

javascript - 高度为 100% 并向左右延伸的图像

javascript - 声明的功能不起作用

html - 根据背景反转文本颜色

javascript - jQuery panzoom 缩放所有元素