如何在 CSS 中垂直居中内联元素

发布于 2024-10-06 12:44:46 字数 305 浏览 0 评论 0原文

这似乎是一个愚蠢的问题,但我没有从 vertical-align 获得预期的结果。那么...

  1. vertical-align:center 是否将具有此属性的项目的子项目居中,或者将项目本身居中 > 在其父级中具有此属性?

  2. 对我来说,“中心”意味着项目的上边距和容器的顶部填充之间的距离,并且项目的底部边距和容器的底部填充是相同的。情况似乎并不总是如此。内联元素的“底部”是文本的基线吗?

谢谢!

This may seem like a silly question, but I am not getting the expected results from vertical-align. So…

  1. Does vertical-align:center center the child items of the item that has this property, or does it center the item itself that has this property, within its parent?

  2. To me, “center” means the distances between the item’s top margin and the container’s top padding, and the item’s bottom margin and the container’s bottom padding are the same. This doesn’t seem to always be the case. Is the “bottom” of an inline element the baseline of the text?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

比忠 2024-10-13 12:44:46

请看这里: http://www.w3schools.com/css/pr_pos_vertical-align .asp

据此,vertical-align:middle 使项目本身根据父项位于中间。

Please take a look here: http://www.w3schools.com/css/pr_pos_vertical-align.asp

According to that, vertical-align:middle make the item itself in middle according to the parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文