2015-02-11 74 views
0

需要帮助才能在不滚动的情况下在父级上显示最内部的div。 当子div显示:block时,我不想在父div上滚动。 和我不能删除.divrelative {位置:相对;}, 和我有固定的父母的高度。如何解决此类div位置相关问题

.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>

回答

1

您谈到 “在父”,在这种情况下,如果接受的重叠,只需删除 “overflow-y:auto” 规则。

.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; 
 
}
<div class="parent"> 
 
    <div class="divrelative"> 
 
     <div class="child"></div> 
 
    </div> 
 
</div>

+0

对不起,我是不是我的问题说清楚,但我有固定HIGHT。如果父div的内容增加了滚动必须出现。 – 2015-02-11 09:52:45

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;}