Flexbox对齐项目:中心

发布于 2025-02-07 07:56:10 字数 824 浏览 2 评论 0 原文

因此,基本上我的问题是,每当我想使用Align-Intems:带有H1和Nav-Bar的中心时,它都行不通。我的意思是,这两者都居中,但不太正确。这是我感兴趣的代码的一部分:

<header class="main-header">

  <h1>The Code Magazine</h1>

  <nav>
    <a href="blog.html">Blog</a>
    <a href="#">Challenges</a>
    <a href="#">Flexbox</a>
    <a href="#">CSS Grid</a>
  </nav>
</header>

当我只选择H1和NAV的容器时,CSS应该可以工作,然后将其设置为flex:

.main-header {display:flex flex ;准项目:中心; }

但是当我这样做时,这是结果: 这就是看起来

,这就是它看起来的样子:

这是我想要的结果

希望有人可以在这里帮助我,我在CSS中是很新的。谢谢。

So basically my problem is that whenever I want to use align-items: center with an h1 and a nav-bar, it doesn't work. I mean, it centers both but not quite right. This is the part of the code I'm interested in:

<header class="main-header">

  <h1>The Code Magazine</h1>

  <nav>
    <a href="blog.html">Blog</a>
    <a href="#">Challenges</a>
    <a href="#">Flexbox</a>
    <a href="#">CSS Grid</a>
  </nav>
</header>

The css should work when I just select the container for both the h1 and the nav, and set it to flex like this:

.main-header { display: flex; align-items: center; }

but when I do that this is the result:
This is how it looks

And this is how it's supossed to look:

This is the result I want

Hope someone could help me out here, I'm quite new in CSS. Thanks.

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

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

发布评论

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

评论(1

没企图 2025-02-14 07:56:10

您可以比较较低的病例和上情况,请尝试此

You compare between lower case and upper case, try this https://codesandbox.io/s/dazzling-cache-dds7id?file=/index.html:246-281

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