CSS 属性 min-height 能够设置元素的最小高度。这样能够防止 {{cssxref("height")}} 属性的应用值小于 min-height 的值。
{{InteractiveExample("CSS Demo: min-height")}}
```css interactive-example-choice min-height: 150px;
```css interactive-example-choice
min-height: 7em;
```css interactive-example-choice min-height: 75%;
```css interactive-example-choice
min-height: 10px;
```html interactive-example
This is a box where you can change the minimum height.
If there is
more content than the minimum the box will grow to the height needed by the
content.
```css interactive-example
#example-element {
display: flex;
flex-direction: column;
background-color: #5b6dcd;
justify-content: center;
color: #ffffff;
}
当 min-height 大于 {{cssxref("max-height")}} 或 {{cssxref("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
- {{cssxref("<length>")}}
- : 定义
min-height为一个绝对数值。
- : 定义
- {{cssxref("<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({{cssxref("<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
{{cssinfo}}
Formal syntax
{{csssyntax}}
示例
Setting min-height
table {
min-height: 75%;
}
form {
min-height: 0;
}