【发布时间】:2017-06-15 20:07:20
【问题描述】:
我已经阅读了很多答案并尝试了很多关于如何在 div 中隐藏滚动条的代码,但答案几乎总是针对具有固定大小的 div,解决方案是隐藏滚动条在包装器 div 中,然后在工作 div 中将滚动条移出(隐藏)屏幕。但是要让它工作,你必须知道 div 的大小,并且我所有的 div 都是使用 width:% 计算的。
有人可以告诉我如何在使用 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;
}
还有位置:绝对;使它与我所提出的其他类似问题有所不同。目前我可以隐藏滚动条,但是当我调整浏览器窗口的大小时,你可以看到它的一部分伸出来。
【问题讨论】:
-
所以你想隐藏滚动条,但仍然可以滚动?
-
它带走了滚动条,还可以滚动。所以我确实把它放在了一个包装 div 中,并试图将滚动条与窗口隔开,但是当我把窗口变大(比如在更大的屏幕上)时,你可以再次看到一半的滚动条......跨度>
-
stackoverflow.com/questions/23294091/… 这基本上是我尝试过的,但它不适用于“position:absolute”以及“width:32%”之类的东西