You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

max-height设为100%时某表格滚动失效,设为500px正常求助

问题:max-height设为100%时表格滚动条异常

当将.card-box的max-height设置为500px时,滚动条正常显示;但设置为100%时,其中一个表格始终不会出现滚动条,另一个表格却能正常工作。

SCSS代码:

.card-box {
  box-shadow: 0 4px 24px 0 rgb(34 41 47 / 10%);
  margin-bottom: 8px;
  background-color: #fff;
  background-clip: border-box;
  border: 0 solid rgba(0, 0, 0, 0.125);
  border-radius: 0.5rem;
  padding: 10px;
  max-height: 100%;
  overflow: scroll;

  .ant-tabs-tab {
    font-weight: bold;
  }

  .ant-table-tbody {
    color: #222;
  }

  .h6-title {
    color: blue !important;
    font-weight: bold !important;
    font-size: 32px !important;
    margin-left: 5px !important;
  }
}

设置为500px时的效果:
设置为500px时的效果

设置为100%时的效果:
设置为100%时的效果

问题原因

max-height: 100%的生效依赖父元素的明确高度值,如果.card-box的上级父元素没有设置height: 100%或固定像素高度,浏览器会把100%解析为auto,容器会被内部内容完全撑开,自然不会触发滚动条。而固定值500px是明确高度限制,内容超出就会显示滚动条。

解决方案

  1. 给父元素设置明确高度:确保.card-box的所有上级父元素都添加height: 100%,让max-height:100%能基于父元素高度计算。
  2. 使用视口单位替代:把max-height:100%改成height: 100vh(占视口高度的100%),如果页面有顶部导航栏,可通过calc调整,比如height: calc(100vh - 80px)(80px为导航栏高度)。
  3. 调整Tabs面板样式:给Ant Design的Tabs内容容器(.ant-tabs-content)或对应面板添加height: 100%和overflow: auto,确保表格所在面板能继承容器高度并触发滚动。

内容的提问来源于stack exchange,提问作者Jing c

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 00:30:55