我很努力地理解flexbox容器如何与其他块交互。只需在我的页面上放置一个flexbox,我就可以做我想做的事。但是当我混合其他页面元素时,事情变得很奇怪。问题似乎是空间分配。如何设置flexbox容器的高度,使其使用“剩余空间”
我的Flexbox容器似乎需要一个明确的高度。如果我没有指定,我不会得到包装行为。我不确定如何指定flexbox容器的高度。
如果我将flexbox容器的高度设置为100%,它将根据需要进行包装,但我被滚动条卡住以至于无法使用:我已经分配了100%以上的高度。我想在flexbox容器上分配100px。所以我需要使Flexbox容器的高度达到100% - 100px。我无法混合绝对和相对测量。而且,往下看,我宁愿不必一定要做这个数学计算,它会成为一个维护的麻烦。
下面是一个事情出错的例子。我想在页面顶部有一些说明。说明应该跨越页面的宽度。在下面的空间中,我想要一组按钮。根据需要,按钮应该换行以使用多列。
我可以通过按钮flexbox容器内的说明使其工作。但是,它不会像我想要的那样100%,它会因我的按钮而变得混乱。
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
border: 1px solid #A00;
}
.instructions {
height: 100px;
background: linear-gradient(to bottom, #ffffff 0%, #999 100%);
}
.container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 80%;
}
.button {
width: 200px;
height: 50px;
margin: 10px;
background: linear-gradient(to bottom, #ffffff 0%, #BBB 100%);
border: 1px solid #CCC;
text-align: center;
}
</style>
</head>
<body>
<div class="instructions">Instructions go here.</div>
<div class="container">
<div class="button">This is Button 1</div>
<div class="button">Thar be Button 2</div>
<div class="button">Yarr, button 3</div>
<div class="button">Hey that is a nice looking button.</div>
<div class="button">Click Me!</div>
</div>
</body>
</html>
这是你试图做什么? http://codepen.io/gc-nomade/pen/jBYbYZ。可以从http://stackoverflow.com/questions/25098042/fill-remaining-vertical-space-with-css-using-displayflex/25098486或http://stackoverflow.com/questions/23090136/how-can- i-make-my-flexbox-layout-take-100-vertical-space/23090449如果不重复 –