Expand a div to fill the remaining width

前端 未结 21 1230
一生所求
一生所求 2020-11-21 22:21

I want a two-column div layout, where each one can have variable width e.g.

21条回答
  •  囚心锁ツ
    2020-11-21 23:04

    flex-grow - This defines the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion. It dictates what amount of the available space inside the flex container the item should take up.

    If all items have flex-grow set to 1, the remaining space in the container will be distributed equally to all children. If one of the children has a value of 2, the remaining space would take up twice as much space as the others (or it will try to, at least). See more here

    .parent {
      display: flex;
    }
    
    .child {
      flex-grow: 1; // It accepts a unitless value that serves as a proportion
    }
    
    .left {
      background: red;
    }
    
    .right {
      background: green;
    }
    Left 50%
    Right 50%

提交回复
热议问题