`)
- : 使单元格的基线,与该行中所有以基线对齐的其他单元格的基线对齐。
- `top`
- : 使单元格内边距的上边缘与该行顶部对齐。
@@ -91,37 +95,40 @@ vertical-align: unset;
可以是负数。
+## 形式定义
+
+{{CSSInfo}}
+
### 形式语法
{{csssyntax}}
## 示例
-### HTML
+### 基础示例
+
+#### HTML
```html
- An
image with
- a default alignment.
+
+ 默认对齐方式的图像
- An
- image with a text-top alignment.
+ 字体顶部(text-top)对齐的图像
- An
- image with a text-bottom alignment.
+ 字体底部(text-bottom)对齐的图像
- An
- image with a middle alignment.
+ 中部(middle)对齐的图像
```
-### CSS
+#### CSS
```css
img.top {
@@ -135,23 +142,135 @@ img.middle {
}
```
-### 结果
+#### 结果
+
+{{EmbedLiveSample("基础示例")}}
+
+### 行内盒的垂直对齐
+
+#### HTML
+
+```html-nolint
+
+top:
+middle:
+bottom:
+super:
+sub:
+
+
+
+text-top:
+text-bottom:
+0.2em:
+-1em:
+20%:
+-100%:
+
+```
+
+```css hidden
+#* {
+ box-sizing: border-box;
+}
-{{EmbedLiveSample("示例")}}
+img {
+ margin-right: 0.5em;
+}
+
+p {
+ height: 3em;
+ padding: 0 0.5em;
+ font-family: monospace;
+ text-decoration: underline overline;
+ margin-left: auto;
+ margin-right: auto;
+ width: 80%;
+}
+```
+
+#### 结果
+
+{{EmbedLiveSample("行内盒的垂直对齐", '100%', 160, "", "")}}
+
+### 表格单元格中的垂直对齐
+
+此示例,我们有一个表格包含一行共六个单元格。该行设置 `vertical-align` 的默认值为 `bottom`。
+
+- 前四个单元格分别设置它们自己的 `vertical-align` 值,这些值会覆盖行的默认值。
+- 第五个单元格没有设置任何 `vertical-align` 值,因此继承行的值。
+- 第六个单元格仅用于确保单元格有足够的高度,以便观察效果。
+
+#### HTML
+
+```html
+
+
+ baseline |
+ top |
+ middle |
+ bottom |
+ Row's style |
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
+ pretium felis eu sem mattis vulputate.
+ |
+
+
+```
+
+#### CSS
+
+```css
+table {
+ margin-left: auto;
+ margin-right: auto;
+ width: 80%;
+}
+
+table,
+th,
+td {
+ border: 1px solid black;
+}
+
+td {
+ padding: 0.5em;
+ font-family: monospace;
+}
+
+.bottom {
+ vertical-align: bottom;
+}
+
+.baseline {
+ vertical-align: baseline;
+}
+
+.top {
+ vertical-align: top;
+}
+
+.middle {
+ vertical-align: middle;
+}
+```
+
+#### 结果
+
+{{EmbedLiveSample("表格单元格中的垂直对齐", '100%', 230, "", "")}}
## 规范
{{Specifications}}
-{{cssinfo}}
-
## 浏览器兼容性
{{Compat}}
## 参见
-- [Typical use cases of Flexbox, section "Center item"](/zh-CN/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox#Center_item)
-- {{Cssxref("line-height")}}, {{Cssxref("text-align")}}, {{Cssxref("margin")}}
-- [Understanding `vertical-align`, or "How (Not) To Vertically Center Content"](http://phrogz.net/css/vertical-align/index.html)
-- [Vertical-Align: All You Need To Know](https://christopheraue.net/design/vertical-align)
+- [弹性盒子的典型用例](/zh-CN/docs/Web/CSS/CSS_flexible_box_layout/Typical_use_cases_of_flexbox#元素居中)
+- {{Cssxref("line-height")}}、{{Cssxref("text-align")}}、{{Cssxref("margin")}}
+- [理解 `vertical-align`,如何(不)垂直居中内容](http://phrogz.net/css/vertical-align/index.html)
+- [Vertical-Align:你要知道的事](https://christopheraue.net/design/vertical-align)