This is because of the real opportunity to find out the true height of the element in which you want to center vertically. To understand this, first think about how automatic horizontal centering works. You have a div that you gave it the width (fixed or percentage). Width can be calculated to a certain extent. If a fixed width, great. If it is flexible or responsive (in percent), at least you have a range that will span the width before it reaches the next breakpoint. You take this width, minus everything inside, and divide the remainder on both sides.
Now, with this information, how could the browser calculate an infinite number of variations in which your div will grow vertically? Keep in mind that element size, text wrapping, paddings, and responsiveness will also change the width and make the text look farther and farther and farther on it.
Is this an impossible task? In fact, CSS has spent time and effort on this? Probably not worth their time.
And this is basically the answer that I am telling my students.
But ... donβt worry! Bootstrap v4 alpha calculated vertical centering !
EDIT
Sorry to edit this late, but I thought you might want to consider this solution in order to center vertically, and it's pretty simple using calc function
<div class="foo"></div> .foo { background-color: red; height: 6em; left: calc(50% - 3em); position: absolute; top: calc(50% - 3em); width: 6em; }
See HERE
LOTUSMS Dec 31 '15 at 23:05 2015-12-31 23:05
source share