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; }