Reputation: 9647
I have two columns which have the style: flex:1
They are within a div which has display: flex
so the columns can have an equal height.
How may I vertically align content in these divs? I have tried setting the margin-top and margin-bottom to auto, but that destroys the heights of the divs.
.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>
Upvotes: 1
Views: 47
Reputation: 2771
Utilize property align-items: center;
in parent div, and background-color
better set at parent 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>
Upvotes: 2