Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Line height property, how it works (simple)

So in this simple example I have as final result:

alt text

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:

alt text


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!!

like image 541
Trufa Avatar asked Dec 14 '10 22:12

Trufa


People also ask

What does line-height 1.5 mean?

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 .

How many pixels is 1.5 line-height?

Google runs a 1.5 line height for its body there, or 16px font size and a line-height of 24px.

What is CSS line-height normal?

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.

What is the difference between height and line-height in CSS?

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.


1 Answers

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.

like image 172
Jarrett Widman Avatar answered Sep 22 '22 11:09

Jarrett Widman