我已經閱讀了很多答案,並嘗試了很多關於如何在div中隱藏滾動條的代碼,但答案几乎總是針對具有固定大小的div,解決方法是將滾動條隱藏在包裝div中,然後在工作區中將滾動條從屏幕上移開(隱藏)。但爲了這個工作,你必須知道div的大小,我所有的div都使用width:%來計算。CSS - 隱藏div中沒有固定寬度的滾動條
有人可以給我一個想法如何隱藏顯示與CSS的div中的滾動條,看到我使用的是Angular2框架,並且不想在其中包含javascript/jquery。
HTML:
<div id="boks3">
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
* <br>
</div>
<div id="stack1">
<div id="boks1">
</div>
<div id="boks5">
</div>
</div>
<div id="stack2">
<div id="boks2">
</div>
<div id="boks4">
</div>
</div>
CSS:
#stack1 {
position: absolute;
width: 100%;
height: 100px;
background-color: #000000;
}
#boks3,
#boks1,
#boks2,
#boks4,
#boks5 {
background-color: #ff3333;
width: 32%;
position: absolute;
margin-left: 33.5%;
padding: 0px 0px 0px 5px;
z-index: 3;
height: 100px;
text-align: left;
overflow: auto;
}
#boks1 {
background-color: #ff6666;
margin-left: 2%;
z-index: 1;
height: 100px;
}
#boks2 {
background-color: #ff4d4d;
margin-left: 17%;
z-index: 2;
height: 100px;
}
#boks5 {
background-color: #ff0000;
margin-left: 65%;
z-index: 1;
text-align: right;
height: 100px;
}
#boks4 {
background-color: #ff1a1a;
margin-left: 50%;
z-index: 2;
text-align: right;
height: 100px;
}
#stack1:hover #boks1,
#stack1:hover #boks5 {
background-color: yellow;
z-index: 4;
}
#stack2:hover #boks2,
#stack2:hover #boks4 {
background-color: green;
z-index: 4;
}
而且位置:絕對的;使它與我所感受到的其他類似問題不同。目前我可以隱藏滾動條,但是當我調整瀏覽器窗口的大小時,可以看到它的一部分突出顯示。
所以,你要隱藏滾動條,上面的代碼的更多細節,但仍然能夠滾動? – mhatch
它帶走了滾動條,但也能夠滾動。所以我把它放在一個wrapper div中,試圖將滾動條放在窗口外面,但是當我把窗口放大時(比如在一個更大的屏幕上),你可以再次看到滾動條的一半...... –
http ://堆棧溢出。com/questions/23294091/hide-scroll-bar-of-nested-div-but-still-make-it-scrollable這基本上是我嘗試過的,但它不適用於「position:absolute」以及某些東西像「寬度:32%」 –