Skip to content

max-height overflow-y:auto 的滚动条冲突

开发过程中遇到了一个 CSS 滚动条去不掉的问题,后证实导致问题的样式如下:

css
.box {
  max-heigth: 300px;
  overflow-y: auto;
}

折腾了好久,才搞清楚是因为 normalize.css 重置了 line-heigth 的值为 1.15,经过测试,此处有两种解决办法

其一是设置 box 的 line-height,line-height 值要大于 1.31005(使用 Chrome V102 测试)

css
.box {
  line-height: 1.5;
}

其二是使 box 的高度再大一点点,貌似最少得 2px

css
.box {
  padding-bottom: 2px;
}

到这里可以正常解决了。

Release time: 6/15/2022, 4:05:00

Last updated:

⟣ Growing, with you. ⟢