Can't seem to figure out how to vertically align one title, a paragraph and a link inside a card. I tried using vertical-align utilities but they're only for inline elements.
This is what my code looks like:
.second {
background: gray;
}
.card-text {
font-size: 12px;
}
.card-title {
font-size: 29px;
}
.btn {
font-size: 12px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="col-6">
<div class="card">
<div class="card-block">
Some other text goes here
</div>
<div class="card-block">
<div class="second p-5">
<img src="https://placehold.it/200x200" class="rounded-circle float-left mr-4" height="200">
<h4 class="card-title mb-2">John Doe</h4>
<p class="card-text mb-2">Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. </p>
<a href="#" class="btn btn-primary py-1 px-3">Click Here</a>
</div>
</div>
</div>
</div>
The image is supposed to be on the left, while the rest of the elements are middle aligned beside it.
Answer: Use the align-items-center Class In Bootstrap 4, if you want to vertically align a <div> element in the center or middle, you can simply apply the class align-items-center on the containing element.
One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.
Vertically align content by setting the css property vertical-align on the card-col and align content horizontally by using text-align or use the helper classes card-row-valign-bottom and card-row-valign-top on the card-row to vertically align all columns inside the row.
There are several different solutions. Here's one way using the flexbox utils...
https://www.codeply.com/go/pB8HWQ0HCv
<div class="col-6">
<div class="card">
<div class="card-block">
Some other text goes here
</div>
<div class="card-block d-flex">
<img src="https://placehold.it/200x200" class="rounded-circle mr-4 my-auto" height="200">
<div class="second">
<h4 class="card-title mb-2">John Doe</h4>
<p class="card-text mb-2">Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. </p>
<a href="#" class="btn btn-primary py-1 px-3">Click Here</a>
</div>
</div>
</div>
</div>
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With