How to stretch children to fill cross-axis?

前端 未结 1 1017
自闭症患者
自闭症患者 2020-12-07 12:45

I have a left-right flexbox:

1条回答
  •  眼角桃花
    2020-12-07 13:31

    • The children of a row-flexbox container automatically fill the container's vertical space.

    • Specify flex: 1; for a child if you want it to fill the remaining horizontal space:

    .wrapper {
      display: flex;
      flex-direction: row;
      align-items: stretch;
      width: 100%;
      height: 5em;
      background: #ccc;
    }
    .wrapper > .left
    {
      background: #fcc;
    }
    .wrapper > .right
    {
      background: #ccf;
      flex: 1; 
    }
    Left
    Right

    • Specify flex: 1; for both children if you want them to fill equal amounts of the horizontal space:

    .wrapper {
      display: flex;
      flex-direction: row;
      align-items: stretch;
      width: 100%;
      height: 5em;
      background: #ccc;
    }
    .wrapper > div 
    {
      flex: 1; 
    }
    .wrapper > .left
    {
      background: #fcc;
    }
    .wrapper > .right
    {
      background: #ccf;
    }
    Left
    Right

    0 讨论(0)
提交回复
热议问题