CSS Flexbox - 当一列包含多个部分时高度相同吗?

标签 css flexbox

我有一个简单的问题。我有一个基本的 flex 盒布局。一列占据布局的 2/3,另一列占据三分之一。它们都有一个紫色半透明标题 (.85),其内容位于不透明的黑框中。

http://codepen.io/StuffieStephie/pen/XdoBqL

body {
  	background: url('http://www.amazingwallpaperz.com/wp-content/uploads/Black-and-Purple-Abstract-Cool-Backgrounds-Wallpaper.jpg') center center;
    background-size: cover;
  font-family: 'Open Sans';
  
}
#featuredSlide, #featuredSlide img {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}


.container {
  display: -webkit-flex;
  display: flex;
  justify-content: space-between;
  color: #fff;
}


.sect {
	box-sizing: border-box;
	width: 32%;
	  -webkit-flex: 1;
          flex: 1;
	margin: 30px;		text-align: center;
}
.sect + .sect {
  	margin-left: 10px;
}
.sect.feat {width: 65%;
  -webkit-flex: 2;
          flex: 2;

}

.sect .cont {
		background:#414141;
		padding-top: 40px;
		padding-bottom: 30px;
		border-radius: 0 0 5px 5px;

}

.sect h2 {
		background:#414141;
				background-color: rgba(52,41,109,.85);
				margin-bottom: 0;
				text-align: center;
				text-transform: uppercase;
				font-size: 2em;
				font-weight: 300;
				padding: 30px 10px;
				border-radius: 5px 5px 0 0;
}
<head><link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600' rel='stylesheet' type='text/css'>
 </head>
<body>
  <div class="container">

<div class="sect feat">		
	<h2> Featured Guests &amp; Programming</h2>

<div class="cont">

<!-- SLIDE SHOW -->
 <div id="featuredSlide" class="owl-carousel">
<img src="http://placehold.it/800x300/5d64a8">
  
</div> <!-- CLOSING SLIDE SHOW DIV TAG --></div>
</div>

<div class="sect">		
	<h2> News </h2>

<div class="cont">Some thrilling article</div>
</div>


</div>

<div class="clearfix"></div>
  
</body>

两个 .sect 元素的高度相同。我希望两个 .sect .cont 元素具有相同的高度。我知道我可以通过将 background-color 设置为 .sect 来使它们看起来相同的高度,但这会破坏我的标题的透明度。

有什么想法吗?

最佳答案

您可以添加flex-direction: column;给您.sect类,并给你的 .cont A类flex-grow: 1 。这将使.cont div 占据 .sect 的剩余高度类。

.sect {
  display: flex;
  flex-direction: column;
}

.cont {
  flex-grow: 1;
}

CodePen

关于CSS Flexbox - 当一列包含多个部分时高度相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37057160/

相关文章:

css - flexbox:在 Safari 中垂直分布元素

html - 仅使用 FLEX 和 CSS 构建进度步骤 UI 组件 - 帮助标记定位?

css - flexbox中每个元素根据其内容占用大小,为什么有的时候会把内容传给另一行?

css - 左 div 滚动和右 div 拉伸(stretch)布局高度/跨浏览器兼容?

html - 如果一个元素位于可变宽度包装器中,则垂直对齐两个元素

html - 无法在 html/php 网站中查看嵌入的 .jpg

css - 用于包装元素并具有动态宽度的固定高度容器的 Flexbox

html - 如何在 phonegap 应用程序的标题上设置内嵌图标和文本?

jquery - Logo 不会滑落(HTML、CSS、jQuery)

css - Flexbox 元素不会到达容器的底部?