如果不需要,请在pre中隐藏滚动条

时间:2022-06-02 20:32:07

The spec says 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.

在我的网站上,我经常在

 -Block中发布代码。由于这没有预定义的宽度,但周围的div确实有一个最大值(定义为百分比),似乎我无法弄清楚如何实现以下内容:如果代码块不是太宽,则隐藏水平滚动条。如果超出宽度,则显示滚动条。任何提示?我想我已经尝试了overflow-x和-y的大多数组合,但似乎没有人做我想要的。

1 个解决方案

#1


101  

Use:

使用:

overflow-x: auto;

auto tells the browser to only show a scrollbar if the content exceeds the width of the box.

如果内容超出框的宽度,则auto告诉浏览器仅显示滚动条。

#1


101  

Use:

使用:

overflow-x: auto;

auto tells the browser to only show a scrollbar if the content exceeds the width of the box.

如果内容超出框的宽度,则auto告诉浏览器仅显示滚动条。