[英]Flexbox not displaying full width of page
I'm trying to use Flexbox to create my own grid. 我正在尝试使用Flexbox创建自己的网格。 I don't want to use Bootstrap or any other framework, so please don't link any of them.
我不想使用Bootstrap或任何其他框架,所以请不要链接其中任何一个。
In my flex-container
, I want to display two sections which are both 100% of the page's width. 在我的
flex-container
,我想显示两个部分,它们都是页面宽度的100%。 So one section should be positioned on top of the other. 因此,一个部分应该位于另一部分的顶部。 Instead, each section is being given 50% of the page's width even when I explicitly defined 100%.
取而代之的是,即使我明确定义了100%,也会为每个部分提供页面宽度的50%。 I have no idea why this is happening.
我不知道为什么会这样。 The browser's developer tools don't lead me to any conclusions either.
浏览器的开发人员工具也无法得出任何结论。
I reconstructed the problem in a jsFiddle . 我在jsFiddle中重构了这个问题。 I get the expected result if, let's say, I define one section to be 7/12 the page's width and the other section to be 5/12 the page's width.
如果我将一个部分定义为页面宽度的7/12,将另一部分定义为页面宽度的5/12,则可以得到预期的结果。
HTML HTML
<div class="flex-container">
<div class="flex-12">
<h4>Title</h4>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
</div>
<div class="flex-12">
<h4>Title 2</h4>
</div>
</div>
Need to tell the container to permit wrapping as the default is nowrap
. 需要告诉容器允许包装,因为默认为
nowrap
。
.flex-container {
display: flex;
flex-wrap:wrap;
}
You can use also use flex-direction column: 您还可以使用flex-direction列:
.flex-container {
display: flex;
flex-direction: column;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.