首页 > 解决方案 > 考虑溢出内容的大小进行定位

问题描述

是否有一种仅限 CSS/HTML 的方法来考虑溢出内容的大小?考虑下面的例子:

.outerZeroSize {
  width: 0px;
  height: 0px;
  overflow: visible visible;
}

.innerContent {
  width: 200px;
  height: 300px;
}

.belowContent {
  
}
<div class="outerZeroSize">
  <div class="innerContent">
    Some content<br/>
    Some more content <br/>
    And some more
  </div>
</div>
<div class="belowContent">Content below</div>

divbelowContent中的文本最终位于innerContent.

问题:由于heightofinnerContent300px,我想出belowContent现在300px下面outerZeroSize(而不是在上面)。这对 CSS/HTML 可行吗?

约束:

相关问题(从 React Virtualized Table 的角度来看)。

标签: htmlcssoverflow

解决方案


只需在. _belowContent

.outerZeroSize {
  width: 0px;
  height: 0px;
  overflow: visible visible;
}

.innerContent {
  width: 200px;
  height: 300px;
}

.belowContent {
  margin-top: 300px;
}
<div class="outerZeroSize">
  <div class="innerContent">
    Some content<br/>
    Some more content <br/>
    And some more
  </div>
</div>
<div class="belowContent">Content below</div>


另一种解决方案是搬进belowContentouterZeroSize

.outerZeroSize {
  width: 0px;
  height: 0px;
  overflow: visible visible;
}

.innerContent {
  width: 200px;
  height: 300px;
}

.belowContent {
  width: 200px;
}
<div class="outerZeroSize">
  <div class="innerContent">
    Some content<br/>
    Some more content <br/>
    And some more
  </div>
  <div class="belowContent">Content below</div>
</div>


推荐阅读