Make flex-grow expand items based on their original size

前端 未结 4 2004
再見小時候
再見小時候 2020-11-22 12:07

I have 3 buttons in a row which all vary in width. I want them to all gain width the same to fill the remaining width of the row, so the widest will still be wider than the

4条回答
  •  囚心锁ツ
    2020-11-22 13:05

    Using flex property you can set proportions:

    .button {
      display: inline-block;
      padding: 10px;
      color: #fff;
      text-align: center;
    }
    
    .row {
      display: flex;
    }
    
    .button--1 {
      background: red;
      flex: 1 1 auto;
    }
    
    .button--2 {
      background: green;
      flex: 2 1 auto;
    }
    
    .button--3 {
      background: blue;
      flex: 3 1 auto;
    }

提交回复
热议问题