我想水平和垂直居中div与视差背景图像。我试过bootstrap 4
类d-block
,mx-auto
,text-center
。它水平居中,但不垂直居中。如何将其垂直居中?
.parallax_bg {
background: url(assets/img/corinne-kutz-211251.jpg);
background-size: cover;
height: 100%;
min-height: 100%;
overflow: auto;
}
.parallax {
background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
}
.parallax_text > p {
font-size: 20px;
}
<section data-stellar-background-ratio="0.5" class="parallax parallax_bg text-center mx-auto d-block">
<div class="parallax_text">
<h3><em>Venenatis Nisl Porta</em></h3>
<p>Lorem vestibulum gravida ipsum non velit aliquam</p>
<a class="btn btn-primary mt-3" href="#">Read More <i class="fa fa-angle-double-right" aria-hidden="true"></i></a>
</div>
</section>
只需申请position: relative
该parallax
课程,然后将以下CSS应用于该parallax_text
课程:
.parallax_text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句