I have a parent, child, and grandchildren divs
. The grandchildren need to be displayed in rows, not columns. I'm trying to get the child to have the same width as the grandchildren, (the child's children,) but at the same time, I want the parent to retain its height of the grandchildren.
I tried making the child to position: absolute
, but the problem with that is, the parent doesn't retain the child, and grandchildren's height.
How can I make the parent have the same height as its descendants, while having a different width. And have the child have the same width as the grandchildren?
*,
*:before,
*:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#wrapper {
background-color: lightblue;
width: 220px;
}
#innerWrapper {
display: flex;
background-color: blueviolet;
}
.item {
background-color: tomato;
width: 100px;
height: 100px;
border: 1px solid blue;
margin: 5px;
flex: 1 0 auto;
}
#other {
background-color: yellow;
width: 300px;
height: 250px;
}
<div id="wrapper">
<div id="innerWrapper">
<div class="item">Item - 1</div>
<div class="item">Item - 2</div>
<div class="item">Item - 3</div>
<div class="item">Item - 4</div>
<div class="item">Item - 5</div>
<div class="item">Item - 6</div>
</div>
</div>
<div id="other">I'm another element</div>