移除了错误的 max-height 限制
.modal-body 添加了 max-height: calc(95vh - 140px)max-height 限制,让 flex 布局自然工作确保 footer 永不被压缩
.modal-footer {
flex-shrink: 0 !important; // 🔥 关键!
background: white !important;
z-index: 10;
position: relative;
}
优化 body 的 flex 属性
.modal-body {
flex: 1 1 auto !important; // 允许增长和缩小
overflow-y: auto !important; // 内容过长时滚动
min-height: 0; // 允许正确缩小
// ❌ 移除了 max-height 限制
}
.modal-body 出现滚动条.modal-container (max-height: 95vh, display: flex, flex-direction: column)
├─ .modal-header (flex-shrink: 0) ← 固定高度,不压缩
├─ .modal-body (flex: 1 1 auto, overflow-y: auto) ← 自动填充,内部滚动
└─ .modal-footer (flex-shrink: 0 !important) ← 固定高度,永不压缩
// ❌ 错误的做法
.modal-body {
max-height: calc(95vh - 140px); // 这会限制 body 高度
// 结果: body 太小,footer 被挤出容器外
}
// ✅ 正确的做法
.modal-body {
flex: 1 1 auto; // 自动占据剩余空间
min-height: 0; // 允许缩小到适合的大小
// 结果: body 自动适应,footer 始终可见
}
flex-shrink: 0 = 不允许缩小,保持原始高度flex-shrink: 1 (默认) = 允许缩小,在空间不足时会被压缩排查步骤:
检查 .modal-footer 的样式:
flex-shrink: 0 !important; // 必须存在
background: white !important; // 必须存在
检查是否有其他CSS覆盖了这些属性
清除浏览器缓存,强制刷新 (Ctrl+Shift+R)
排查步骤:
@media (max-width: 768px) 中的 footer 样式max-heightmin-height 是否生效可能原因:
display: none 隐藏opacity: 0.modal-body 的 max-height 限制.modal-footer 的 flex-shrink: 0 !importantmax-height: calc(95vh - 140px) 给 body核心原则:
max-heightflex-shrink: 0 !importantmax-height 就够了关键点:
flex-shrink: 0 !important 是确保 footer 永远可见的唯一关键!