So in this simple example I have as final result:
This is a very simple question but I simply can't get my head around it.
To achieve the vertical centering of the numbers I used:
line-height:100px;
Which works great and have been doing it trial and error basis.
My question is specifically why the line-height:50px;
just gets if half of the way.
If the small
div
has a height of 100px
and I an positioning relative to it, shouldn't the half of it center it to the half.
This specially puzzles me since, when I center a div:
I would use: margin:50px 0 0 50px;
to get this:
I realize this question might be an overkill since the answer might be (probably will be very simple), so sorry! but I guess it is better the "why doesn't this work" questions ;)
Thanks in advance!!
line-height: 1.5 (without units) will mutiply the element's font size by 1.5 to compute the line height. line-height: 150% will take 150% of the element's computed font size to compute the line height, which is equivalent to multiply it by 1.5 .
Google runs a 1.5 line height for its body there, or 16px font size and a line-height of 24px.
The default line-height is about 110% to 120% for the majority of the browsers. The line-height property sets the leading of lines of a text. If the line-height value is greater than the font-size value of an element, the difference will be the leading of text.
Height is the vertical measurement of the container, for example, height of a div. Line-height is a CSS property to specify the line height i.e. the distance from the top of the first line of text to the top of the second. It is the space between the lines of two paragraphs.
The simple answer is that with line-height the character will be in the vertical middle of the line, so a line with a height of 100px has the text in the middle of, thus 50px.
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