Set div to have its siblings width

后端 未结 8 1521
猫巷女王i
猫巷女王i 2020-12-05 09:34

I\'m looking for a CSS solution to the following:-

8条回答
  •  [愿得一人]
    2020-12-05 10:23

    2020 keep it simple...

    Use grid and the fractional unit? Then you can split up into as many equally sized rows or columns as you want:

    .container {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-column-gap: 1em;
    }
    
    .container > div {
      border: 1px solid black;
      padding: 0.5em;
    }
    I'm a part of a grid. I will be split up into equal parts with my other sibling(s) depending on how many columns the grid is given.
    I am a sibling element.

提交回复
热议问题