css flex布局与min-height无法被继承问题

flex 1 0 auto,内含p标签等文字内容超出flex盒子范围怎么办?

<!-- flex布局包裹p标签,p标签内容超出导致flex盒子变长 -->
<div style="display: flex;" class="no-effect">
  <div style="flex: 0 0 80px">我比较短</div>
  <!-- 添加overflow: hidden见效果 -->
  <div style="flex: auto;">
    <p class="no-wrap">我很长,不是开玩笑的,可以长到没边</p>
  </div>
</div>
给auto的盒子,添加overflow: hidden或者设置height或者min-height。由于flex: 1会自动占满剩余空间。height设置为0也没关系。(出现问题的原因是flex: auto中的flex-basis默认值是auto而非常规的0,所以宽度会超出)

mcss布局中min-height无法被继承怎么办
flex布局,纵向的宽度会被默认占满,然后再放入一个子盒子在其中用height: 100%就能被继承宽度。如果出现什么宽度问题,可以用height: 0解决。
完整代码:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      div {
        padding: 5px;
        border: 1px solid #ccc;
        box-sizing: border-box;
      }

      .no-effect {
        align-items: center;
        margin: 100px;
        width: 200px;
        color: #999;
      }

      .no-effect > div:first-of-type {
        margin-right: 10px;
      }

      p {
        color: red;
      }

      .no-wrap {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .testHeight {
        display: flex;
        width: 400px;
        background-color: skyblue;
        min-height: calc(100vh - 96px);
      }
      .childDiv {
        flex: 0 0 auto;
        width: 100px;
        background-color: rgb(203, 135, 235);
      }
      .reChildDiv {
        width: 50px;
        height: 100%;
        background-color: black;
      }
    </style>
  </head>
  <body>
    <!-- flex布局包裹p标签,p标签内容超出导致flex盒子变长 -->
    <div style="display: flex;" class="no-effect">
      <div style="flex: 0 0 80px">我比较短</div>
      <!-- 添加overflow: hidden见效果 -->
      <div style="flex: auto;">
        <p class="no-wrap">我很长,不是开玩笑的,可以长到没边</p>
      </div>
    </div>
    <div class="testHeight">
      <div class="childDiv">
        <div class="reChildDiv"></div>
      </div>
    </div>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值