html - overflow-y 自动隐藏内容

标签 html css overflow

使用 overflow-y:auto

enter image description here

使用 overflow-y:scroll

enter image description here

是否有某种方法可以在滚动条溢出时设置滚动条(并且不隐藏内容),但同时在滚动条没有溢出时将其移除?

当前的CSS:

  max-height: 400px;
  overflow-y: scroll;
  overflow-x: hidden; <-- do not want horizontal scroll under any circumstances, want the div to respond to the content

最佳答案

您可以尝试在您的列表中使用负 margin-right 和具有正 padding-right 的父容器元素来补偿负子边距。

.container {
    width:100px;
    padding-right:10px;
}
ul {
    max-height:100px;
    overflow-y:scroll;
    background-color:yellow;
}
.list-one {
}
.list-two {
    margin-right:-10px;
}
<div class="container">
<ul class="list-one">
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
</ul>
<ul class="list-two">
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
    <li>list item</li>
</ul>
</div>

关于html - overflow-y 自动隐藏内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31160789/

相关文章:

Android webView - 如何更改 webView 对话框的背景颜色?

html - 如何使用滚动条在一行上生成大量堆叠的 div

css - 我在 CSS 中使用什么 Overflow 来垂直滚动

从溢出 :hidden 过渡时的 iOS Safari 渲染错误

javascript - onClick函数改变html

html - knockout 可见绑定(bind)样式显示内联不起作用

jquery - 我回来后的动态网页

javascript - 鼠标离开的jquery问题

javascript - 对选定文件进行 Canvas 旋转和调整大小操作时,加载程序图像不显示

html - 在iphone中的固定位置