What is line-height:1?

后端 未结 6 1917
迷失自我
迷失自我 2020-12-29 02:36

It is a question about the appointment of line-height.

I began study of css. line-height: Examples appointing 20px or a unit are often found. It is sometimes line-

相关标签:
6条回答
  • 2020-12-29 02:48

    It's a multiple of the font size. From the CSS 2.1 Candidate recommendation: »The used value of the property is this number multiplied by the element's font size.«

    0 讨论(0)
  • 2020-12-29 02:59

    Possible Values

    number :

    Sets a number that will be multiplied with the current font-size to set the distance between the lines

    length :

    Sets a fixed distance between the lines

    % :

    Sets a distance between the lines in % of the current font size

    take from http://www.w3schools.com/css/pr_dim_line-height.asp

    0 讨论(0)
  • 2020-12-29 03:01

    If no unit is supplied e.g. "line-height: 1.5" the distance between the lines is set as this number multiplied with the current font size.

    1.5 x font-size

    0 讨论(0)
  • 2020-12-29 03:02

    It seems that line-height doesn't need a unit (detailled article).

    The property line-height can accept unitless number values. You can also give line-height united values, though generally you shouldn’t. But unitless numbers are just fine for this property.

    0 讨论(0)
  • 2020-12-29 03:02

    Also note: "1" does not equal "normal" - 1 is exactly the same height as the font-size, so the lines in a multi-line element such as a paragraph will be snug up against each other, while normal adds the expected spacing between the lines.

    Using the font shorthand:

    font: font-style font-variant font-weight font-size/line-height font-family;
    

    appears to default the line-height to normal if it isn't specified. For example:

    body{
        line-height:1; /* as seen in Eric Meyer's reset css */
    }
    p{
        font:normal normal normal 14px "Times New Roman", Times, serif;
    }
    

    will result in all paragraphs having a normal line-height, overriding the 1 set for the body, while

    p{
        font:normal normal normal 14px/1 "Times New Roman", Times, serif;
    }
    

    will retain the line-height of 1 (which in this example would be 14px).

    0 讨论(0)
  • 2020-12-29 03:02

    According to w3schools and w3.org line-height:1; is valid and means the following: Sets a number that will be multiplied with the current font-size to set the distance between the lines.

    0 讨论(0)
提交回复
热议问题