如何解决这种div位置相关问题

时间:2015-02-11 09:39:34

标签: html css

需要帮助才能在没有滚动的情况下显示父项的最内层div。 当子div显示时,我不想在父div上滚动:block。 我不能删除.divrelative {position:relative;}, 我已经确定了父母的高度。

.parent{background:#ccc; padding:10px; height:100px; overflow-y:auto;}

.divrelative{position:relative;}

.child{ background:#fff; width:80%; height:180px; border:1px solid #000; position:absolute; z-index:9999;}
<div class="parent">
      <div class="divrelative">
          <div class="child"></div>
      </div>
</div>

2 个答案:

答案 0 :(得分:1)

你谈到了父母的问题&#34;在这种情况下,如果您接受重叠,只需删除&#34; overflow-y:auto&#34;规则。

&#13;
&#13;
.parent {
   background: #ccc;
   padding: 10px;
   height: 100px;
}

.divrelative {
   position: relative;
}

.child {
   background: #fff;
   width: 80%;
   height: 180px;
   border: 1px solid #000;
   position: absolute;
   z-index: 9999;
}
&#13;
<div class="parent">
   <div class="divrelative">
      <div class="child"></div>
   </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

将位置更改为absolute

.parent{background:#ccc; padding:10px; height:100px;}

.divrelative{position:relative;}

.child{ background:#fff; width:80%; height:180px; border:1px solid #000; position:absolute; z-index:9999;}