Flexbox不填充宽度

发布于 2025-02-13 16:19:32 字数 646 浏览 0 评论 0原文

我目前正在尝试使用FlexBox创建标头。但是,我试图将两个容器与最左边的两个容器对齐,而一个div向右对齐,但似乎并没有弹性箱容器填充宽度的100%。这会导致问题,因为我无法将DIV一直推向右侧。我该如何解决?

header {
  width: 100%;
  display: flex;
  flex-direction: row;
}

header .header-sm {
  justify-content: right;
}

header .logo {
  justify-content: left;
}

header nav {
  justify-content: left;
}
<header>
  <div class="logo"></div>
  <nav></nav>
  <div class="header-sm"></div>
</header>

感谢您的帮助!

I'm currently trying to create a header using flexbox. However, I'm trying to align two containers to the far left, and one div to the far right, but it doesn't seem like the flexbox container is filling 100% of the width. This causes problems, since I cant push the div all the way to the right. How do I fix this?

header {
  width: 100%;
  display: flex;
  flex-direction: row;
}

header .header-sm {
  justify-content: right;
}

header .logo {
  justify-content: left;
}

header nav {
  justify-content: left;
}
<header>
  <div class="logo"></div>
  <nav></nav>
  <div class="header-sm"></div>
</header>

Thank you for your help!

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

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

发布评论

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

评论(1

甜心小果奶 2025-02-20 16:19:32

Jusify-content只能放置在Flex容器级别上,

但在您的情况下,如果您想将特定物品对齐在容器右侧的特定项目,则可以使用Margin-Left播放:auto

header {
    width: 100%;
    display: flex;
    flex-direction: row;
    background: red;
}

header * {
  margin: 5px;
  border: solid 1px blue;
}

header .header-sm {
    margin-left: auto
}
<header>
   <div class="logo">test</div>
   <nav>test</nav>
   <div class="header-sm">test</div>
</header>

justify-content can only be placed at the flex container level

but in your case if you want to align a specific item to the right of the container you can play with margin-left: auto

header {
    width: 100%;
    display: flex;
    flex-direction: row;
    background: red;
}

header * {
  margin: 5px;
  border: solid 1px blue;
}

header .header-sm {
    margin-left: auto
}
<header>
   <div class="logo">test</div>
   <nav>test</nav>
   <div class="header-sm">test</div>
</header>

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