如何在以下示例中垂直对齐标题,而不将position: absolute
与transform: translateY(-50%)
等结合使用,也不设置固定px金额的手动线高?在示例中,我给父母一个固定的高度,但这仅用于演示目的,解决方案不应该依赖于此。
.newsletter {
background: black;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
height: 140px; }
.newsletter__column {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-line-pack: center;
align-content: center; }
.newsletter__title {
margin: 0;
padding: 0;
color: white;
background: red;
}
<section class="newsletter">
<div class="newsletter__column">
<h1 class="newsletter__title">Newsletter</h1></div>
</section>