Html 如果不需要,在 pre 中隐藏滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1675414/
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
Hide scrollbar in pre if not needed
提问by data
The specsays that a horizontal scrollbar is supposed to be always shown if overflow-x: scroll is set.
该规范说,如果设置了 overflow-x: scroll ,则应该始终显示水平滚动条。
On my website I often post code in a <pre>
-Block. As this has no predefined width, but the surrounding div does have a maximum (defined as percentage), it seems that I can not figure out how to achieve the following:
In case a code block is not too wide, hide the horizontal scrollbar.
If it exceeds the width, show a scrollbar.
Any hints? I think I have tried most of the combinations of overflow-x and -y, but none seem to do what I want.
在我的网站上,我经常在<pre>
-Block 中发布代码。由于这没有预定义的宽度,但周围的 div 确实有一个最大值(定义为百分比),似乎我无法弄清楚如何实现以下内容:如果代码块不太宽,隐藏水平滚动条。如果超过宽度,则显示滚动条。任何提示?我想我已经尝试了大多数溢出-x 和-y 的组合,但似乎没有一个能达到我想要的效果。
回答by Konrad Rudolph
Use:
用:
overflow-x: auto;
auto
tells the browser to only show a scrollbar if the content exceeds the width of the box.
auto
告诉浏览器仅在内容超过框的宽度时才显示滚动条。