我有两列具有样式的列:flex:1
它们位于具有display: flex
的div内,因此列可以具有相同的高度。
我如何垂直对齐这些div中的内容?我已经尝试将margin-top和margin-bottom设置为auto,但这会破坏div的高度。
.container { width: 100%; display: flex; }
.col { width: 50%; flex:1; background:pink;}

<div class="container">
<div class="col"><h1>This is text</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div>
<div class="col"><img src="https://ichef.bbci.co.uk/images/ic/448x252/p062kcgj.jpg" style="width:100px;" /></div>
</div>
&#13;
答案 0 :(得分:2)
在父div和背景颜色中使用属性align-items: center;
更好地设置在父div。
.container { width: 100%; display: flex; align-items: center; background:pink; }
.col { width: 50%; flex:1; }
<div class="container">
<div class="col"><h1>This is text</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div>
<div class="col"><img src="https://ichef.bbci.co.uk/images/ic/448x252/p062kcgj.jpg" style="width:100px;" /></div>
</div>