2016-12-05 77 views
-1

我的第一個想法是把position: fixed,但是當我這樣做時,內部div就消失了。它並沒有隱藏在其他任何東西之後,因爲我試圖改變距離頂端的距離。如何在div滾動時創建div?

這裏是我的代碼:

#menu { 
 
    background-color: green; 
 
    width: 200px; 
 
    min-height: 600px; 
 
    flex: 0 0 auto; 
 
    order: 1; 
 
} 
 
    
 
#menu #buttons { 
 
    background-color: black; 
 
    width: auto; 
 
    height: 300px; 
 
    margin: 15px; 
 
    position: relative; 
 
}
<div id="menu"> 
 
    <div id="buttons"></div> 
 
</div>

現在,大格是Flexbox的,這也是一個div中的元素。我希望這不是問題的根源,但如果沒有其他解決方法,我會改變這個設置。提前致謝。

+0

當你測試的東西,頭腦設置你的標籤裏面的一些內容,否則他們可能不會顯示在所有。空div是高度:0;寬度:100%emty div固定爲高度:0&寬度:0.您的代碼段不會顯示出太多麻煩。我真的不明白你想做什麼 –

回答

0

我建議使用內部div的overflow-y: scroll。另外請注意,外部div應該使用position: fixed並且最好使用width: 100%作爲內部div。

另外,你應該用一些內容填充內部div,除非它不會正確顯示。

0

您是不是要找:

#menu { 
 
    background-color: green; 
 
    width: 200px; 
 
    height: 300px; 
 
    overflow-y:scroll; 
 
} 
 

 
#buttons { 
 
    background-color: black; 
 
    width: auto; 
 
    height: 500px; 
 
    margin: 15px; 
 
    z-index:1; 
 
}
<div id="menu"> 
 
    <div id="buttons"></div> 
 
</div>