line-height
理解 CSS 行高的继承
by Wenwei He
HTML
<h2>line-height: 15px</h2>
<p>父元素:line-height: 15px; <br> 子元素:font-size: 30px;</p>
<div class="px-line-height"><p>如果默认字体为 16px,父元素行高为 15px,那么子元素继承 15px 行高</p></div>
<hr>
<h2>line-height: 1.5em</h2>
<p>父元素:line-height: 1.5em; <br> 子元素:font-size: 30px;</p>
<div class="em-line-height"><p>如果默认字体为 16px,父元素行高为 1.5em,那么子元素继承 16px*1.5=24px 行高</p></div>
<hr>
<h2>line-height: 150%</h2>
<p>父元素:line-height: 150%; <br> 子元素:font-size: 30px;</p>
<div class="percent-line-height"><p>如果默认字体为 16px,父元素行高为 150%,那么子元素继承 16px*150%=24px 行高</p></div>
<hr>
<h2>line-height: 1.5</h2>
<p>父元素:line-height: 1.5; <br> 子元素:font-size: 30px;</p>
<div class="nounits-line-height"><p>如果默认字体为 16px,父元素行高为 1.5,那么子元素继承 30px*1.5=45px 行高</p></div>
CSS
h2 { color: #FF004E }
h2+p { color: #1D74E0 }
div p { font-size: 30px; color: #191E24; }
.px-line-height { line-height: 15px; }
.em-line-height { line-height:1.5em; }
.percent-line-height { line-height:150%; }
.nounits-line-height { line-height:1.5; }