如何避免Flex容器高度塌陷?
2025-04-15
15
参考资料
设置固定高度
.flex-container { display: flex; height: 300px; /* 固定高度 */ }使用
min-height.flex-container { display: flex; min-height: 200px; /* 最小高度 */ }设置
align-items属性.flex-container { display: flex; align-items: stretch; /* 默认值,子项拉伸填充高度 */ }子项设置高度
.flex-item { height: 100%; /* 子项继承容器高度 */ }使用
flex-grow.flex-item { flex-grow: 1; /* 子项扩展填充剩余空间 */ }清除浮动(如果存在浮动元素)
.flex-container::after { content: ""; display: table; clear: both; }
示例:
<div class="flex-container" style="display: flex; min-height: 200px;"> <div class="flex-item" style="flex-grow: 1; background: lightblue;"></div> </div>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
本文来自《西里网 . html 网页设计》 -- 发布时间:2025-03-29
本页链接:https://html.ciilii.com/show/news-936.html
原创声明:本篇文章均为西里网原创,由《DeepSeek-R1 模型》自动生成。内容真实性仅供参考学习。
本作品采用 知识共享署名—非商业性使用—相同方式共享 4.0 国际许可协议 (CC BY-NC-SA 4.0) 进行许可。
