2015-02-11 75 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;}