html - Flexbox 高度被忽略

标签 html css height flexbox

有人可以帮我解决这个问题吗?我不知道为什么我的高度:50%;以下 flexbox 规则被忽略。为了 visibility ,我在所有 child 周围都画了边框。两行的高度应相等。

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>

最佳答案

您的 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/

关于html - Flexbox 高度被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40053553/

相关文章:

css - span 没有出现在它的 div 里面

Jquery,.height() 在页面刷新时改变,但在加载时不改变

css - 将 div 定位到没有绝对位置的已经居中的内容

html - 如何用颜色填充 100% 的网页

javascript - 如何获取 ID 作为值和名称以显示在 dropdownlist php 中

html - 如何右对齐 <p> 标签?

html - 如何使用 htaccess 强制使用 http- 而不是 https

php - if isset($_POST 问题

html - css 网格中的长文本不会内联

html - CSS :nth-child() psuedo selecting