I am having an issue getting text to be centered vertically within a div. I've tried both CSS and bootstrap options, but not having luck. The closest that I get is with using align-items: center
, however, the test is still offset from what should be middle.
Current code:
.code-quote {
max-width: 70%;
height: 40px;
background-color: #707793;
display: flex;
align-items: center;
justify-content: center;
}
.code-text {
font-size: 1.5rem;
color: #3BBA9C;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="row">
<div class="col">
<div class="code-quote mx-auto">
<h3 class="code-text">This is my text</h3>
</div>
</div>
</div>
This is what I get:
If I remove the align-items: center
, then it's much closer to the top of the element.