I’m trying to have the text centered vertically within the entire yellow space. I’ve been trying to implement the “align-items-center” onto the row, as suggested in their documentation, as well as the “my-auto” class. I’m not sure what I am doing wrong.
#heading-cont {
background-color: #F7CE38;
height: 10rem;
}
.white {
color: white;
}
.title {
font-family: 'Montserrat', Arial, sans-serif;
text-transform: uppercase;
font-weight: 300;
}
.description {
font-family: 'Pathway Gothic One', Arial, sans-serif;
font-weight: 400;
text-transform: uppercase;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<section class="header">
<div class="container-fluid" id="heading-cont">
<div class="row">
<div class="col-sm-12 my-auto">
<h1 class="title white text-center">Digital</h1>
<h4 class="description white text-center">This is the description.</h4>
</div>
</div>
</div>
</section>
4
Answers
(I assume you meant “vertically center”; since there’s only one column in your example, there’s nothing to align it with.)
The
container-fluid
is assigned a minimum height of 10rem in Bootstrap. To vertically center your text, you need to stretch therow
to match it:You will need to give the row a height of 100% so that there is room to center the text in.
You can add a class (in my example
.x
) to#heading-cont
and apply the following CSS to it to make it a flexbox container and vertically center its contents:https://codepen.io/anon/pen/GMdazJ
Firstly, use the bootstrap 4 classes like they were meant to be used :
class=”d-flex flex-column justify-content-center”, and then you don’t need to add the height to the row. Don’t make seperate css rules that just repeat existing utility classes if you don’t have to.
https://codepen.io/anon/pen/oGyrPg