比方说下面这段代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
.b1{
display: flex;
border: 1px solid #000;
flex-direction:column;
}
.b2{
width: 30px;
height: 30px;
border: 1px solid #000;
}
</style>
</head>
<body>
<div class="b1">
<div class="b2"></div>
<div class="b2"></div>
</div>
</body>
</html>
效果是这样的,外层div宽度占满了一行:
注意:我的要求是父盒子不定宽,子盒子定宽。
参考:
https://developer.mozilla.org...