css - 强制滚动条显示内容是否溢出

标签 css

我有这个 div 类 feedback-rounds-container。它是固定的高度和宽度,有时内容会溢出。为了让用户清楚,我强制显示滚动条,覆盖浏览器设置,但现在它一直显示,即使内容没有溢出 div。

如果内容溢出,我想让它一直显示,但如果内容没有溢出,我根本不希望它显示。有什么办法可以做到这一点(希望在纯 css 中)?

.feedback-rounds-container {
  overflow-y: scroll;
  height: 80px;
  width: 200px;
  border: solid 1px #ddd;
}
.feedback-rounds-container::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 7px; 
}
.feedback-rounds-container::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.5);
    -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, 0.5); 
}
<div class="feedback-rounds-container">Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here. Content here.</div>

<br>

<div class="feedback-rounds-container">Content here</div>

最佳答案

使用auto代替scroll;这将在内容溢出时显示垂直滚动条。

.feedback-rounds-container {
  overflow-y: auto;
}

关于css - 强制滚动条显示内容是否溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39726549/

相关文章:

css - 为什么这个 CSS 无效?

html - Column flexbox : wrap to width limit, 然后增长高度?

jquery - 使用 jquery 和 css 定位 div 标签的值

html - 无法选择文本

css - 有没有在线生成跨平台(包括IE6)框阴影的工具?

html - 登录页面到 jhipster 应用程序?

html - 图像放大

javascript - 如何聚焦文本区域点击主类

CSS&HTML : How to put an image(for example X/check) inside a checkbox when you hover it

html - 动态显示 "show more"