jquery - 即使没有可滚动的内容,也会出现 css 溢出滚动条

标签 jquery html css

我像下面的代码一样使用 overflow:scroll,我遇到的问题是即使没有文本,滚动条仍然显示。
w3schools 上的演示:http://www.w3schools.com/cssref/tryit.asp?filename=trycss_overflow 你会看到,即使你不能水平滚动(向左或向右),仍然有一个滚动条。如果没有任何内容可滚动到,我试图将它放在滚动条不出现的地方。希望这是有道理的

<style type="text/css">
  div.scroll {
    background-color: #00FFFF;
    width: 100px;
    height: 100px;
    overflow: scroll;
  }
</style>
<p>overflow:scroll</p>
<div class="scroll">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div>

最佳答案

我认为您正在寻找 overflow: auto

Mozilla's Documentation on Overflow

The overflow CSS property is shorthand for the overflow-x and overflow-y properties, and specifies what to do when content is too large to fit in its block formatting context.

The options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area.

自动

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 like Firefox provide scrollbars if content overflows.

关于jquery - 即使没有可滚动的内容,也会出现 css 溢出滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10196008/

相关文章:

phonegap 应用程序中的 Android 滚动条?

javascript - 8不小于或等于30?

jquery - 使用 jQuery mobile 将内容设置为全屏,没有溢出或滚动

javascript - 如何在 HTML 标签内使用 Javascript 变量?

CSS 文件输入隐藏路径

css - 到达 css 节点时遇到问题

javascript - 附加div内容jquery

javascript - 如何使用 jQuery 更改链接的 "href"属性具有特定的 "href"?

php - 基于 PHP 变量嵌入 YouTube 视频

css - 我如何在 material-ui 中使用伪元素::之前,::之后