如何给 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/