I am trying to center a text vertically so it looks nice using Twitter Bootstrap 3 and CSS but I can’t get it to work. I have the following HTML:
<div class="col-md-3 vcenter">
<img src="https://dummyimage.com/30x30/000/fff" class="pull-left">
</div>
<div class="col-md-9 vcenter">
<h3>header 3</h3>
</div>
Then I am applying the following CSS (found here):
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
Here is Fiddle with an example of what’s currently happening. Can I get some help?
3
Answers
If able, can you modify your HTML to use a single column row?
Attached JS Fiddle: https://jsfiddle.net/qgas0tej/3/
Here is a possible solution that may be what you’re looking for:
HTML:
CSS:
There’s nothing wrong with your vcenter style. The problem lies in the bootstrap margin of h3 tag not being vertically consistent, detailed below.
This shows the bootstrap inconsistent vertical margin:
Just adding margin to your h3 tag makes it vertically consistent and fixes the issue:
CSS:
HTML:
Solution in JSFiddle