ALIGN-CONTENT中心不工作,而是对齐中心工作

发布于 2025-02-09 06:53:38 字数 590 浏览 0 评论 0原文

最近,我一直在了解有关Flexbox的更多信息,我只是偶然发现了一些意外的行为。

我有一个div,其中包含一个标头元素:

<div>
    <h2> Hello </h2>
</div>

DIV

{
  display: flex;
  justify-content: center;
  align-content: center;
  flex-direction: column;
}

我正在尝试水平(在横轴中)将标头置为中心,而我的理解是Align-Content:Center会这样做。

但是,仅当我将Align-feelf应用于标题时,它才能有效。

知道什么可能导致这种行为?我以为flex项目上的Align-Content等同于每个孩子的Align-eff。为什么只有指定align-self才能工作?

Recently I've been learning more about flexbox, and I just stumbled across some unexpected behavior.

I have a div, with a header element inside of it:

<div>
    <h2> Hello </h2>
</div>

The div has

{
  display: flex;
  justify-content: center;
  align-content: center;
  flex-direction: column;
}

I'm trying to center my header horizontally (in the cross-axis), and my understanding is that align-content: center would do that.

However, it only works if I apply align-self: center to the header.

Any idea what might be causing this behavior? I thought align-content on the flex item was equivalent to align-self on each of the children. Why is it only working if I specify align-self?

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

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

发布评论

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

评论(2

如日中天 2025-02-16 06:53:38

无需将属性应用于标题,只需包括Align-Items:Center;而不是Align-Content:中心对CSS,它将完美地工作。

No need to apply the property to the header , Just include align-items: center; instead of align-content:center to the CSS and it will work perfectly.

薔薇婲 2025-02-16 06:53:38

flex示例

官方文档

尝试

flex-direction: row;

display: flex;
align-items: center;
justify-content: center

Flex examples

official documentation

Try

flex-direction: row;

Or

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