【问题标题】:chrome, overflow: auto shows horizontal scroll bar whenever vertical scroll bar is shownchrome,溢出:每当显示垂直滚动条时自动显示水平滚动条
【发布时间】:2016-07-02 18:53:51
【问题描述】:

我有一种情况,我使用 max-width 和 max-height,每当内部内容越过 max-height 垂直滚动条时应该显示,并且每当内部内容越过 max-width 水平滚动条时应该显示。

在下面的场景中,只要出现垂直滚动条,即使内部内容没有超过最大宽度,也会显示水平滚动条。

我尝试使用不同的 box-sizing 值,因为它看起来像垂直滚动条占据了部分宽度,使水平滚动条出现,但它仍然没有帮助。

.p {
  position: absolute;
  max-width: 200px;
  max-height: 400px;
  overflow: auto;
  border: 1px solid red;
}

.c {
  position: relative; 
  height: 500px;
  border: 1px solid blue;
}



<div class="p">
    <div class="c">
      vhjjujfhjsdfd
    </div>
  </div>

JSBIN

【问题讨论】:

    标签: html css google-chrome overflow


    【解决方案1】:
    1) you can use
    <div style="width:100px;height:100px;overflow:scroll;"></div> 
    

    这将永久设置滚动条。但是,如果您只想在高度/宽度超过指定值时显示滚动条,请使用“overflow:auto”作为 -

    <div style="width:100px;height:100px;overflow:auto;">
    

    2) 因为你的单词太长并且没有中断尝试添加 word-break: 将所有内容都转换为 C 类

    .p {
      position: absolute;
      max-width: 200px;
      max-height: 400px;
      overflow: auto;
      border: 1px solid red;
    }
    
    .c {
         position: relative; 
         height: 500px;
         border: 1px solid blue;
        word-break: break-all;
    }
    
    
    
    <div class="p">
        <div class="c">
          vhjjujfhjsdfd
        </div>
      </div>
    

    【讨论】:

    • 我知道每个功能的概念,请正确阅读问题。从技术上讲,滚动条只有在超过指定的最大宽度时才会出现。即使在最大宽度内,滚动条也会出现在这里。即使这个词很长,它也在最大宽度之内,如果我想使用断词,我也不会使用滚动。
    • 将 max-width 更改为 width 并将 max-height 更改为 height 可能会解决您的问题。
    • 我只需要最大宽度和最大高度
    猜你喜欢
    • 2014-08-27
    • 2011-11-21
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 2020-03-08
    • 2021-11-13
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多