Vertical Scrollbar leads to horizontal scrollbar

后端 未结 5 1220
遇见更好的自我
遇见更好的自我 2020-12-15 03:12

My CSS looks like this:

div.SOMECLASS {
  position: absolute;
  max-height: 300px
  height: auto;
  width: auto;
  overflow: auto;
  ...
}

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 03:49

    Just figured out a pretty passable solution (at least for my version of this problem).

    I assume the issue with width: auto is that it behaves similarly to width: 100vw; the problem is that when the vertical scrollbar appears, the viewport width remains the same (despite the ~10px scrollbar), but the viewable area (as I'm calling it) is reduced by 10px.

    Apparently defining width by percentage defines it in terms of this "viewable area", so changing your code to:

    div.SOMECLASS {
      position: absolute;
      max-height: 300px
      height: auto;
      width: 100%;
      overflow: auto;
      ...
    }
    

    should allow the content to rescale properly!

    p.s. You can also instead add overflow-x: hidden, which will stop the horizontal scrollbar from appearing, instead simply cutting ~10px off of the right side of your div when the vertical scrollbar appears.

提交回复
热议问题