相对位置和溢出自动

时间:2018-06-13 12:12:23

标签: css position overflow

我遇到溢出问题:auto和position relative?我的代码示例是:

<div id="grandparent" style="overflow-y: auto;">
    <div id="parent" style="position: relative;">
        <div id="child" style="position: absolute;"></div>
    </div>
</div>

我希望#child超过#grandparent div,但由于#parent和他的位置相对而导致溢出:/

1 个答案:

答案 0 :(得分:-2)

div, div.child::after {
  border: 3px dashed #ccc;
  padding: 20px;
}

div::before { content: attr(class); }

.grandparent { overflow: auto; }
.parent { position: relative;}
.child::before{ content: " " }
.child {position: relative; overflow: auto; }
.child::after {content: attr(class); position: absolute; height: 60px; background: black; color: white;
}
<div class="grandparent">
  <div class="parent">
    <div class="child"></div>   
  </div>
</div>

这是您的答案,但似乎不实用 因为实际上不能以这种方式实现

请清楚地询问您的问题或提供更实际的示例

相关问题