css 垂直对齐_CSS垂直对齐属性

css 垂直对齐

介绍 (Introduction)

vertical-align defines the vertical alignment for the content of a table cell or for an inline element against the rest of the inline flow.

vertical-align定义表格单元格的内容或内联元素相对于其余内联流的垂直对齐方式。

vertical-align can take a % or length value, or it can take one of the following 8 keywords:

vertical-align可以采用length值,也可以采用以下8个关键字之一:

  • baseline: The default. Baseline of the element aligned to the baseline of the parent.

    baseline :默认值。 元素的基线与父元素的基线对齐。

  • bottom: Bottom of the element aligned to the complete bottom of the line.

    bottom :元素的底部与行的整个底部对齐。

  • middle: Middle of the element aligned to half the x-height of the parent. The x-height is the height of the text without the character ascenders or descenders.

    middle :元素的中间,对齐到父元素的x高度的一半。 x高度是不含字符的上升或下降字符的文本的高度。

  • sub: Baseline of the element aligned to the subscript baseline of the parent.

    sub :元素的基线与父元素的下标基线对齐。

  • super: Baseline of the element aligned to the superscript baseline of the parent.

    super :元素的基线与父对象的上标基线对齐。

  • text-bottom: Bottom of the element aligned to the bottom of the text.

    text-bottom :元素的底部与文本的底部对齐。

  • text-top: Top of the element aligned to the top of the text.

    text-top :元素的顶部与文本的顶部对齐。

  • top: Top of the element aligned to the top of the line.

    top :元素的顶部与行的顶部对齐。

If a length value is provided, the element is aligned at the specified length above the baseline of the parent.

如果提供了长度值,则元素将在父级基线上方的指定长度处对齐。

If a % value is provided, the element is aligned at the specified % above the baseline of the parent, with the % being a reference to the line-height.

如果提供值,则该元素在父级基线上方指定的%处对齐,该%是对行高的引用。

Here’s an example using vertical-align:

这是一个使用垂直对齐的示例:

.avatar {
  vertical-align: middle;
}

例子 (Examples)

It can be hard to visualize the effects of the different keyword values for vertical-align, so here are examples with an inline seashell emoji (🐚) placed with different values:

可能很难直观地看到不同关键字值对垂直对齐的影响,因此下面是带有不同值的嵌入式贝壳表情符号(🐚)的示例:

垂直对齐:基线 (vertical-align: baseline)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:底部 (vertical-align: bottom)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:中间 (vertical-align: middle)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:子 (vertical-align: sub)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:超级 (vertical-align: super)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:文本底部 (vertical-align: text-bottom)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:文本顶部 (vertical-align: text-top)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

垂直对齐:顶部 (vertical-align: top)

Sammy sells seashells 🐚 by the seashore.

萨米卖贝壳🐚在海边。

翻译自: https://www.digitalocean.com/community/tutorials/css-vertical-align-property

css 垂直对齐

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值