<分区>
<分区>
似乎 flex-direction: column 根本不起作用。另一方面 flex-direction: row; - 工作完美。您只需将“列”换成“行”即可在下面的代码中看到它:
.flex-container {
display: flex;
flex-direction: column;
height: 400px;
background-color: DodgerBlue;
}
.flex-container>div {
flex-grow: 1;
background-color: #f1f1f1;
margin: 10px;
line-height: 75px;
}
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
在列模式下,display: flex 表现得像常规 display: block 和他的 child 从他那里流出,而不是缩小以适应高度或 max-height: 400px;
这是为什么呢?为什么它只适用于“行”模式?
最佳答案
移除行高或添加 overflow: auto 到容器。基本上它是关于每个 child 制作溢出容器的硬编码高度。
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: column;
height: 400px;
background-color: DodgerBlue;
}
.flex-container>div {
flex-grow: 1;
background-color: #f1f1f1;
margin: 10px;
}
</style>
</head>
<body>
<h1>Flexible Boxes</h1>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
关于html - Flexbox,列的行为与行不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51284613/