【发布时间】:2018-05-22 09:51:21
【问题描述】:
我得到了这个简单的设置,在一个 flex-box 中包含 3 个元素。它们之间有合理的空间。中间的 .center 元素设置为 100% 的宽度。出于某种原因,无论窗口多宽,子元素(链接)都会换行。
链接被包裹到下一行的结果背后的机制是什么?有足够的空间。为什么 .center div 不占用 100% 的剩余空间,所以它们不会换行。以及如何防止这种包装?
PS:我希望 .center div 占据其间 100% 的空间。
<div class="header">
<h1>Title</h1>
<div class="center">
<h1>
TEST TEXT
</h1>
</div>
<div class="nav">
<a>A Link</a>
<a>Another Link</a>
<a>A Third Link</a>
</div>
.header {
background: #ccc;
display: flex;
justify-content: space-between;
}
.nav{
width: fit-content;
}
.center{
width:100%;
background: lightblue;
text-align: center;
}
div a{
background: tomato;
}
【问题讨论】:
-
防止包装很容易,只需要
flex:1jsfiddle.net/vsx239v1/1 ... 因为它更棘手