Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

height vs line-height styling

Tags:

html

css

styling

What is the difference between using these two when dealing with text that will never be more than a single line? They both can produce similar results on the screen from what I can see in regards to the elements on top or on the bottom of the element. Why use line-height at all if so? Height would make more sense to use.

Edit: An example of this a stylized button created from a div with text inside. This will never be multiline. So would line-height be needed for compatibility reasons? or anything I don't know about?

Thanks!

like image 414
EverTheLearner Avatar asked Sep 30 '11 22:09

EverTheLearner


People also ask

What line height should I use?

The perfect line height depends on the design and size of the font itself. There is no magic number that works for all text. A line height of 1.5 times the font size is a good place to start from, and then you can adjust accordingly. Using an 8 point grid system works well when using 1.5 line height.

What is a good line height CSS?

While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size. While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size.

What is the difference between line height 20 pixel and line height 2?

What is the difference between the following line-height settings? line-height: 20px; line-height: 2; The value of 20px will set the line-height to 20px. The value of 2 will set the line-height to twice the size of the corresponding font-size value.

What is the difference between font size and line height?

Sets line height to be equal to a multiple of the font size. If your font size is 10px, your line height will be 10px, 18px, and 20px, respectively. Sets line height as a percentage of the font size of the element. If your font size is 10px, your line height will be 3px, 5px, and 11px respectively.


1 Answers

height is the vertical measurement of the container.

line-height is the distance from the top of the first line of text to the top of the second.

If used with only one line of text I'd expect them to produce similar results in most cases.

I use height when I want to explicitly set the container size and line-height for typographic layout, where it might be relevant if the user resizes the text.

like image 155
Dennis Traub Avatar answered Sep 21 '22 07:09

Dennis Traub