Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "font" ignore "line-height" in CSS while "font-size" doesn't?

Tags:

css

I experienced a very weird behavior. Why does test2 ignore line-height while test1 works fine? (the background-color is just to identify the containers better)

body {
    line-height:0.8;
}

.test1 {
    background:#fdf;
    font-size:24px;
    font-family:Arial,sans-serif;
}
.test2 {
    background:#ffd;
    font:24px Arial,sans-serif;
}

live demo: http://jsfiddle.net/tHUeg/4/

like image 855
user2015253 Avatar asked Feb 03 '26 17:02

user2015253


2 Answers

font is a shorthand property, and using it nukes any specific properties that make it up. Since line-height is included in font (usually seen as 24px/0.8 Arial,sans-serif), it is reset to its default value.

like image 143
Niet the Dark Absol Avatar answered Feb 06 '26 05:02

Niet the Dark Absol


font includes line-height so it is overridden to the default.

https://developer.mozilla.org/en-US/docs/Web/CSS/font

like image 22
James Montagne Avatar answered Feb 06 '26 06:02

James Montagne