"%": is the distance from the inherited parent element;
"No unit": is the child element to calculate the individual line distance eg:
| 12345678910111213141516171819202122 |
<!DOCTYPEhtml><htmllang="en"><head> <metacharset="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> |
Effect
1, when line-height:xx%: body{font-size:14px;line-height:150%;} p{font-size:26px;} The result is: body{line-height:21px;} 14*150%=21p{line-heigt:21px;} Inherit parent element eg:
| 12345678910111213141516171819202122 |
<!DOCTYPEhtml><htmllang="en"><head> <metacharset="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> |
Effect
2, when line-height:x.x: body{font-size:14px;line-height:1.5;} p{font-size:26px;} The result is: body{line-height:21px;} 14*1.5=21p{line-height:39px;} 26*1.5=39
The difference between line-height:150% and line-height:1.5