CSS 属性 min-height 能够设置元素的最小高度。这样能够防止 height 属性的应用值小于 min-height 的值。
CSS Demo: min-height
min-height: 150px;
min-height: 7em;
min-height: 75%;
min-height: 10px;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
This is a box where you can change the minimum height. <br />If there is
more content than the minimum the box will grow to the height needed by the
content.
</div>
</section>
#example-element {
display: flex;
flex-direction: column;
background-color: #5b6dcd;
justify-content: center;
color: #ffffff;
}
当 min-height 大于 max-height 或 height 时,元素的高度会设置为 min-height 的值。
语法
/* <长度> 数值 */
min-height: 3.5em;
/* <百分比> 数值 */
min-height: 10%;
/* 关键词 */
min-height: max-content;
min-height: min-content;
min-height: fit-content(20em);
/* 全局数值 */
min-height: inherit;
min-height: initial;
min-height: unset;
Values
- <length>
- : 定义
min-height为一个绝对数值。
- : 定义
- <percentage>
- : 定义
min-height为一个相对于父容器高度的百分数。
- : 定义
auto- : 浏览器将通过计算为指定元素选择一个
min-height值。
- : 浏览器将通过计算为指定元素选择一个
max-content- : The intrinsic preferred
min-height.
- : The intrinsic preferred
min-content- : The intrinsic minimum
min-height.
- : The intrinsic minimum
fit-content(<length-percentage>)- : Uses the
fit-contentformula with the available space replaced by the specified argument, i.e.min(max-content, max(min-content, argument)).
- : Uses the
Formal definition
Formal syntax
示例
Setting min-height
table {
min-height: 75%;
}
form {
min-height: 0;
}
规范
浏览器兼容性
相关链接
- The box model, box-sizing
- height, max-height
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
