大网数据广告活动
Web 标准与前端开发

min-height

· 52CE 我爱测

CSS 属性 **`min-height`** 能够设置元素的最小高度。这样能够防止 height 属性的应用值小于 `min-height` 的值。

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.
  • min-content
    • : The intrinsic minimum min-height.
  • fit-content(&lt;length-percentage&gt;)
    • : Uses the fit-content formula with the available space replaced by the specified argument, i.e. min(max-content, max(min-content, argument)).

Formal definition

Formal syntax

示例

Setting min-height

table {
  min-height: 75%;
}

form {
  min-height: 0;
}

规范

浏览器兼容性

相关链接

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。