Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20161208】CSS line-height 百分比和数值的区别 #57

Closed
zhongxia245 opened this issue Dec 8, 2016 · 0 comments
Closed

【20161208】CSS line-height 百分比和数值的区别 #57

zhongxia245 opened this issue Dec 8, 2016 · 0 comments

Comments

@zhongxia245
Copy link
Owner

时间:2016-12-08 11:44:54

一、结论

line-height: 150% 不等于 line-height: 1.5
line-height的值为百分比: 子集元素继承父级元素的距离
line-height的值为数值 : 子元素计算各自的行距离

二、例子讲解

1. line-height 为百分比

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{
            font-size:14px;
            line-height:150%;
            background: black;
        }
        p{
            font-size:26px;
            background: gray;
            color: white;
        }
    </style>
</head>
<body>
    <p>你好!</p>
</body>
</html>

效果:

例子1结果

body{font-size:14px;line-height:150%;}
p{font-size:26px;}

//结果就是:
body{line-height:21px;}//14*150%=21
p{line-heigt:21px;}//继承父元素 

2. line-height 为数值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{
            font-size:14px;
            line-height:1.5;
            background: black;
        }
        p{
            font-size:26px;
            background: gray;
            color: white;
        }
    </style>
</head>
<body>
    <p>你好!</p>
</body>
</html>

效果:

说明:

body{font-size:14px;line-height:1.5;}
p{font-size:26px;}
//结果就是:
body{line-height:21px;} //14*1.5=21 
p{line-height:39px;} //26*1.5=39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant