确定渲染树中的元素

问题描述 投票:1回答:1

在Web浏览器的上下文中,Render Tree仅包含将在网页上可见的元素。因此,具有display: none的元素不会进入渲染树。但是我知道渲染树中包括了像height: 0position : absolute; left: 100%这样的元素,即使它们在渲染时在网页上也不可见。那么为什么这些元素仍包含在渲染树中?

javascript html css google-chrome browser
1个回答
0
投票
  • 因为它们仍然可以容纳可见的子节点:

.no-height {
  height: 0;
};
.absolute {
  position: absolute;
}
<div class="no-height">
  <p class="absolute">still here</p>
</div>
  • 因为它们仍然可以具有可见的边框或边距

.no-height {
  height: 0;
  border: 5px solid;
  margin: 120px;
};
<div class="no-height">
</div>
I should be at top
  • 因为它们可能会影响其他可见节点:

.no-height {
  height: 0;
};
<div>
  some inline<div class="no-height"></div>text
</div>
  • ...
© www.soinside.com 2019 - 2024. All rights reserved.