我知道这个问题有很多重复,但是到目前为止,这些都没有。
我有一个宽度未知的div,它使用overflow-y:scroll,但是我想隐藏滚动条并使它仍然可滚动。它居中位于屏幕中间,我该怎么做?
.content-middle {
margin: 0 auto;
text-align: center;
max-height: 81vh;
overflow-y: scroll;
}
<div class="content-middle">
<p>My content is here</p>
</div>
基本上,您要做的是将可滚动元素放在另一个元素内,并将其绝对定位在右侧。(负值)
然后只关注可滚动元素的内容。
body {
overflow: hidden;
}
.content-middle {
margin: 0 auto;
text-align: center;
max-height: 81vh;
overflow-y: scroll;
position: absolute;
width: 100%;
right: -17px;
}
<div class="content-middle">
<p>My content is here</p>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句