-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 对 line-height 的理解及其赋值方式 | ||
|
||
## 概念 | ||
|
||
line-height 指一行文本的高度,包含了字间距,实际上是下一行基线到上一行基线的距离 | ||
|
||
line-height 和 height 都能撑开元素高度 (如果 line-height 和 height 一致时可以实现单行文字的垂直居中) | ||
|
||
|
||
## 计算方式 | ||
|
||
### 带单位的px | ||
|
||
line-height 为 固定值 | ||
|
||
### 纯数字 | ||
|
||
直接 line-height 会把比例传递给后代 | ||
|
||
例如,父级行高为 1.5,子元素字体为 18px,则子元素行高为 1.5 * 18 = 27px | ||
|
||
### 百分比 | ||
|
||
父元素将计算后的值传递给后代 | ||
|
||
例如,父元素行高为 200%,父元素字体为 18px,那么子元素行高为 18 * 200% = 36px |