我有一个小小的CSS问题。我有不同高度的div,我希望父元素的高度是最大元素的高度,而其余元素也要相应地进行 Package 。下面的代码对行(父元素的宽度是最宽元素的宽度)非常有效,但对列就不行了(只需将body类改为column)。有什么想法吗?
body.row #parent {
display: flex;
flex-flow: wrap row;
width: min-content;
}
body.row .child {
display: flex;
flex-direction: row;
border: 1px solid red;
width: max-content;
}
body.column #parent {
display: flex;
flex-flow: wrap column;
height: min-content;
}
body.column .child {
display: flex;
flex-direction: column;
border: 1px solid red;
height: max-content;
width: max-content;
}
<html>
<body class="row">
<div id='parent'>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
</div>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
</div>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
</div>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
<span>3. Line</span>
<span>4. Line</span>
<span>5. Line</span>
<span>6. Line</span>
<span>7. Line</span>
<span>8. Line</span>
</div>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
</div>
<div class="child">
<span>1. Line</span>
<span>2. Line</span>
</div>
</div>
</body>
</html>
2条答案
按热度按时间2w2cym1i1#
在
#parent
上使用display: inline-flex;
。6rqinv9w2#
height: min-content;
将共同应用于所有子级。如果希望子级换行,则必须在#parent
上指定max-height: (somValue)px