CSS max-height / min-height 实例

CSS max-heightCSS min-height1 个文件更新于 2026-04-06
html公开前 25 行,完整代码需登录
<style>
  .maxmin-height-demo {
    background-color: #e8e8e8;
    padding: 10px;
  }
  .maxmin-height-item {
    background-color: #2196F3;
    border: 1px solid #000;
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    padding: 10px;
    margin: 5px 0;
    overflow: auto;
  }
  .max-height {
    max-height: 70px;
  }
  .min-height {
    min-height: 150px;
  }
</style>
<div class="maxmin-height-demo">
  <div class="maxmin-height-item max-height">最大高度 70px(内容超出会滚动)这是一段很长的内容,用来测试最大高度的效果,当内容超过最大高度时会出现滚动条。为了体现效果,这里增加很多有很多很多很多有很多很多很多有很多很多很多有很多很多的内容。</div>

登录后可以查看完整源码、在线编辑并实时预览运行效果。