I'd like media-body
content to be vertically aligned 'middle'.
Here is the markup:
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="..." alt="...">
</a>
<div class="media-body">
I'd like this text to be vertically aligned 'middle'
</div>
</div>
I've tried the following which doesn't work:
.media-body {
vertical-align: middle;
}
Any idea how I can do this?
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.
In Bootstrap 5, if we want to vertically align an <div> element in the middle of a containing element, we can do this by applying the class align-items-center and d-flex on the containing element of that div. Here, the d-flex class has the same effect as that of the display: flex; property in CSS. Example: HTML.
Aligning content to the center of the DIV is very simple in Bootstrap 5, You just have to convert the div into a flex box using d-flex class property and then use the property align-items-center to vertically align the content in the middle of the div.
Since Bootstrap v3.3.0, it's possible to vertically align both the media-object
and the media-body
, by adding the CSS class media-middle
.
For example:
<div class="media">
<div class="media-left media-middle">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
<div class="media-body media-middle">
<h4 class="media-heading">Media heading</h4>
...
</div>
</div>
See: http://getbootstrap.com/components/#media
Incidentally, the docs currently don't make it clear that this works for the media-body
as well. It does, because all media-middle
does is to add a vertical-align: middle;
style to an element, and media-body
already has the style display: table-cell
(as does media-left
and media-right
).
Bootply : http://www.bootply.com/122430
HTML:
<div class="media">
<a class="" href="#">
<img class="media-object custom-media" src="..." alt="..." height="500px" width="500px">
</a>
<div class="media-body">
I'd like this text to be vertically aligned 'middle'
</div>
</div>
CSS:
.custom-media, .media-body{
display:inline;
}
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