CSS 我需要删除溢出的 <DIV> 上的水平滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1400992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I need to remove the Horizontal Scrollbar on an overflown <DIV>
提问by Storm
I have defined a tag with a CSS attribute "overflow" set to "scroll". This is giving me both the vertical and the horizontal scroll bars. I only want the vertical scroll bar. What should i do?
我定义了一个 CSS 属性“溢出”设置为“滚动”的标签。这给了我垂直和水平滚动条。我只想要垂直滚动条。我该怎么办?
回答by Kim Andersen
You could try using the
你可以尝试使用
overflow-y: scroll;
This will give you a vertical scroll-bar...
这将为您提供一个垂直滚动条...
Using
使用
overflow-y: auto;
will only show the scrollbar if it is necessary.
仅在必要时显示滚动条。
回答by Ben Blank
Try using "overflow-y: scroll;
" instead. It's CSS3, but as far as I know, it's supported by every modern browser (IE6+, FF, Opera, Chrome/Safari/WebKit/etc.).
尝试改用“ overflow-y: scroll;
”。它是 CSS3,但据我所知,所有现代浏览器(IE6+、FF、Opera、Chrome/Safari/WebKit/等)都支持它。
A quick explanation of the various overflow
/-x
/-y
values, for those not familiar with them:
各种简单的解释overflow
/ -x
/-y
值,对于那些不熟悉它们:
visible
– The default. Content which does not fit "overflows" the box, usually appearing over or under adjacent content.hidden
– Content which does not fit is "guillotined" — cut off at the edges of the box.auto
– Content which does not fit causes a scroll bar to appear. Does not necessarily cause both scroll bars to appear at once; if content fits horizontally but not vertically, only a vertical scroll bar will appear.scroll
– Similar toauto
, but scroll bar(s) appear whether needed or not. AFAIK, mostly used to prevent centered content from "jumping" if a scroll bar needs to be added to dynamic (e.g. AJAX) content.
visible
– 默认值。不适合的内容“溢出”框,通常出现在相邻内容的上方或下方。hidden
– 不适合的内容被“断头台”——在盒子的边缘被切断。auto
– 不适合的内容会导致出现滚动条。不一定会同时出现两个滚动条;如果内容水平放置而不垂直放置,则只会出现垂直滚动条。scroll
– 与 类似auto
,但无论是否需要都会出现滚动条。AFAIK,如果需要将滚动条添加到动态(例如 AJAX)内容,则主要用于防止居中的内容“跳跃”。
回答by Zoidberg
overflow:auto;
回答by markbaldy
I realize this is a very old question but I stumbled across it today. If, like me, you only want the y-scrollbar and then only when it's needed, I found this works:
我意识到这是一个非常古老的问题,但我今天偶然发现了它。如果像我一样,你只想要 y 滚动条,然后只在需要时,我发现这有效:
.myclass {
overflow-x: hidden;
overflow-y: auto;
}
Cheers, Mark
干杯,马克
回答by Nimsara Madhubashini
overflow-x:hidden;
overflow-y:scroll;