html - 如何在溢出后给当前div添加滚动?

标签 html css

如何给 block 元素添加滚动条?

我使用了overflow-y:scroll,但它立即创建了一个滚动条。我想在我的 div 达到特定高度后滚动。

最佳答案

您应该使用overflow-y: auto在达到元素的高度后滚动。

auto Depends on the user agent. If content fits inside the padding box, it looks the same as visible, but still establishes a new block-formatting context. Desktop browsers provide scrollbars if content overflows. - MDN

Whereas scroll Content is clipped if necessary to fit vertically in the padding box. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content. - MDN

关于html - 如何在溢出后给当前div添加滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72659066/

相关文章:

javascript - 单击目标图标时切换显示 div

html - Div 从屏幕右侧溢出 - iphone

css - A 标签上居中文本的 IE 位置

jquery - 由于名称属性,复选框未显示

html - 在低于特定屏幕分辨率的移动设备上隐藏 div

html - CSS 在大于屏幕的元素之前居中

javascript - 将加载的内容限制在 div 中

javascript - 渐进增强和 "flash of unhidden content"?

html - 指定 h1 字体系列不会更改字体?

css - 内联 block 元素列表中的换行符,即使没有 html 空格和 box-sizing : border-box