父級開啟flex,子級寬度不被壓縮情況


1,如果父級開啟了flex,子級元素的寬度相加大於父級,那么子級元素的寬度會被壓縮

2.不讓子級的寬度壓縮

方法一,在子級添加 flex-shrink: 0;   值為0不被壓縮,

方法二,在其中的一個子級添加一個子級,有寬高,也就是box的孫級,此時box2也不會壓縮

 

 

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>
    .box{
      width: 230px;
      height: 200px;
      border: 1px solid red;
     display: flex;
    }

    .box1{
      width: 100px;
      height: 100px;
      background-color: skyblue;
      flex-shrink: 0;

    }
    .box2{
      width: 100px;
      height: 100px;
      background-color: hotpink;
      
    }

    .box2 .inner{
      width: 100px;
      height: 100px;
    }
    .box3{
      width: 100px;
      height: 100px;
      background-color: yellow;
    }
  </style>
</head>
<body>
  
  <div class="box">
    <div class="box1"></div>
    <div class="box2">
      <div class="inner"></div>
    </div>
    <div class="box3"></div>
  </div>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM