【转】【20161208】line-height 百分比与数值的区别
Closed this issue · 1 comments
zhongxia245 commented
时间:2016-12-08 11:44:54
转自《line-height 百分比与数值的区别》
一、结论
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
hwaphon commented
You really help me! Thanks very much.