em-squarecss
font-size
相關。但並不是徹底相同。<p> <span class="a">Ba</span> <span class="b">Ba</span> <span class="c">Ba</span> </p> p { font-size: 100px } .a { font-family: Helvetica } .b { font-family: Gruppo } .c { font-family: Catamaran }
一行文本,會包含不少個以上所描述的正方形容器。全部這些容器所組成的就是line-box
html
line-box
的高度依賴於其子項的高度瀏覽器
line-box
足以包含全部的子項子項的高
所指==並不是==content-area
的高度行內元素擁有兩個不一樣的高度app
content-area
的高度less
font-size
與font-family
共同做用virtual-area
的高度ide
line-height
line-height
並不是兩行文本baseline
的距離,而是virtual-area
的高度(word,PS等軟件中,使用的是兩行文本baseline
的距離)svg
virtual-area
和content-area
的高度差爲leading
(半行距)wordpress
leading
在content-area
之上,另外一半在下leading
不支持非整數,向上的一半爲向上取整,向下的部分爲向下取整(可能不許確)。因此多數狀況,content-area
會在virtual-area
居中偏下的位置(leading
若恰好爲2的倍數,則content-area
會垂直居中)。<p>
標籤由數個line-box
構成字體
如下的<p>
由三個line-box
組成flex
::first-line
)<p> Good design will be better. <span class="a">Ba</span> <span class="b">Ba</span> <span class="c">Ba</span> We get to make a consequence. </p>
類型
img, input, svg
等inline-block
以及inline-*
inline
元素。好比在flexbox
中,全部的flex
子項。這些元素的高度,由height
,margin
和border
進行計算。
height:auto
height
,line-height
,content-area
的高度都徹底相等。手動設置line-height
,此時僅至關於設置了最小高度
line-height
的常規值文本
line-height
既virtual-area
徹底由font-family
肯定,由字體設計者來定義。所以將設置line-height:1
是很壞的習慣。極可能致使virtual-area
的區域比content-area
要小.
line-height
設置爲一個無單位數,即標識其爲font-size
的對應倍數。padding
以及border
會增長background
的區域,但不會修改content-area
的區域其餘
padding
`margin以及
border會修改
height,
content-area 和
line-box`。baseline
文本
baseline
的具體位置由各字體肯定其餘
img及inline-block等
textarea等
baseline
去對齊父級塊內的匿名內聯元素的baseline
>The baseline of an ‘inline-block’ is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its ‘overflow’ property has a computed value other than ‘visible’, in which case the baseline is the bottom margin edge. * 一個`inline-block`元素,若是裏面沒有`inline`內聯元素,或者overflow不是visible,則該元素的基線就是其margin底邊緣,不然,其基線就是元素裏面最後一行內聯元素的基線 ``` .dib-baseline { display: inline-block; width: 150px; height: 150px; border: 1px solid #cad5eb; background-color: #f0f3f9; } <span class="dib-baseline"></span> <span class="dib-baseline">x-baseline</span> ```
明明尺寸、display水平都是同樣的,結果呢,兩個卻不在一個水平線上對齊,爲何呢?哈哈,上面的規範已經說明了一切。第一個框框裏面沒有內聯元素,所以,基線就是容器的margin下邊緣,也就是下邊框下面的位置;而第二個框框裏面有字符,純正的內聯元素,所以,第二個框框就是這些字符的基線,也就是字母x的下邊緣了。因而,咱們就看到了框框1下邊緣和框框2裏面字符x底邊對齊的好戲。
middle
文本
中點由==元素==的baseline
加上其1/2x-height
的高度,具體可參考字母’x’在CSS世界中的角色和故事。
其餘
將這些元素的中點進行對齊。
x-height
和baseline
相關。font-size:0
,將父級塊內的匿名內聯元素高度置爲0(即保證了該元素的全部線都是一致的)top
/bottom
文本
line-box
的頂部/底部其餘
text-top
/text-bottom
文本
content-area
的頂部/底部其餘
百分比
line-height
屬性的百分比。負值則爲向下數值
vertical-align:baseline
可能致使line-box
高度比line-height
要大。<p> <span>Ba</span> <span>Ba</span> </p> p { font-family: Catamaran; font-size: 100px; line-height: 200px; } span:last-child { font-size: 50px; }
<p> <span>Ba</span> </p> p { line-height: 200px; } span { font-family: Catamaran; font-size: 100px; }
此時line-box
中會存在一個匿名行內元素,字符屬性與<p>
可繼承的字符熟悉值相同。該元素width
爲0,line-height
與<span>
極可能不一致。致使<p>
的高度不爲200px;
//這樣可能更容易理解,Ba就是那個 匿名行內元素,即便沒有在標籤中顯式添加文本內容,也會存在對應高度 <p> Ba <span>Ba</span> </p> p { line-height: 200px; } span { font-family: Catamaran; font-size: 100px; }