Set the width of children to fill the parent

后端 未结 7 1083
日久生厌
日久生厌 2020-12-19 11:46

I want the children of the div fill its width.

now am using a code like this:

7条回答
  •  眼角桃花
    2020-12-19 12:33

    You can make the parent a flexbox and define for the children to grow when there is space available. I removed the width for .child.

    .parent {
      width: 100%;
      display: inline-flex;
      height: 120px;
      background: #000;
      padding: 10px;
      box-sizing: border-box;
    }
    
    .child {
      display: inline-block;
      margin-left: 1%;
      height: 100px;
      background: #ffffd;
      flex-grow: 1;
    }

提交回复
热议问题