I'm trying to vertical align, with pixel perfection in mind, two texts.
One is completely capitalized, the other is not.
http://codepen.io/FezVrasta/pen/EjxJoz
div {
outline: 1px solid red;
height: 31px;
width: 400px;
float: left;
line-height: 31px;
}
span {
display: inline-block;
vertical-align: middle;
}
As you can see, the capitalized text is perfectly centered (20px above and 20px below).
The other one, has 26px above, and 19px below.
I think it always centers the text assuming the higher possible character as center... but I'd like to center the current text considering only the used characters.
Is there a way?
NB: Using CSS tables will not fix the problem.
The vertical-align property can be used in two contexts: To vertically align an inline element's box inside its containing line box. For example, it could be used to vertically position an image in a line of text. To vertically align the content of a cell in a table.
This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.
Use the CSS vertical-align property The vertical-align property is used to vertically center inline elements. The values of the vertical-align property align the element relative to its parent element: Line-relative values vertically align an element relative to the entire line.
Each browser only sets one baseline for the font. It doesn't care if you're using capitals or not. So naturally not every letter can be exactly centered because they have different heights and maybe descenders.
Vertical alignment is more a "close to"-value. When you set vertical-align: top; not all the letters will align to the top and bump the top-border, just the baseline of the font does.
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