Flexbox高度被忽略

时间:2016-10-14 23:52:12

标签: html css height flexbox

有人可以帮我解决这个问题。我不知道为什么我的身高:50%;在以下flexbox中忽略规则。为了能见,我在所有孩子周围都有边界。两行都应该占据相同的高度。

html,
body {
	height: 100%;
}
.container {
    display: flex; 
    position: relative;
    flex-flow: row wrap;
    justify-content: center;
    align-items: stretch; 
    height: 100vh; 
    width: 80%;	
	/*padding-top: 2%;
	padding-bottom: 18%;
    margin: 5% auto 8% auto; */
    background-color: white;
	border: 2px solid red;
}
.container h2 {
	color: orange;
}
.top {
	display: flex;
	flex-flow: row wrap;
	justify-content: center;
	align-items: center;	
	border: 2px solid blue; 	
}
.top * {
	1 1 50%;
	display: flex;
	flex-flow: row wrap;
	justify-content: center;
	align-content: center;
	height: 100%;
}
.bottom {
	display: flex;
	flex-flow: row wrap;
	justify-content: space-around;
	align-items: flex-start;
	border: 2px solid orange;
}
.top,
.bottom {
	flex: 0 0 100%;
	height: 50%;
}
.topa {
	display: flex;
	flex-flow: row wrap;
	justify-content: center;
	align-content: center;
	/* border: 2px solid orange; */
	height: 100%;
	background-color: orange;
}
.topa inner {
width: auto;
height: auto;
}
.topb {
	display: flex;
	flex-flow: row wrap;
	justify-content: center;
	align-content: center;
	border: 2px solid purple; 
	background-color: black;
	height: 100%;
}
<div id="bigwrap">
	<div class="container">
    	<div class="top">
        	<div class="topa">
            	<div class="inner">
            		<img src="chocolate.jpg" width="209" height="205" alt="Picture of kid" /> 
                </div>
            	<div class="inner">
            	    <img src="cookies.jpg" width="209" height="205" alt="Picture of kid" /> 
            </div>
            <div class="topb">
            </div>           
        </div>
        <div class="bottom">
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

你的HTML需要一些清理工作。你的div没有正确打开和关闭。应该是这样的:

<div id="bigwrap">
  <div class="container">
    <div class="top">
      <div class="topa">
        <div class="inner">
          <img src="chocolate.jpg" width="209" height="205" alt="Picture of kid" /> 
        </div>
        <div class="inner">
          <img src="cookies.jpg" width="209" height="205" alt="Picture of kid" /> 
        </div>
        <div class="topb">
        </div>           
      </div>
    </div>
    <div class="bottom">
    </div>
  </div>
</div>

这是一个JSFiddle来演示:https://jsfiddle.net/6pLcn9bu/