嵌套的flexbox,align-items不flex-end [英] Nested flexbox, align-items do not flex-end

查看:111
本文介绍了嵌套的flexbox,align-items不flex-end的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将导航放在底部 flex-end
我不知道是什么导致它不放在底部。我知道我可以把它放在绝对位置,试图避免这种情况。

I'm trying to place the navigation at the bottom with flex-end. I'm not sure what's causing it not to place at the bottom. I know I can place it with position absolute, trying to avoid that.

代码在jsfiddle

<header>
  <div class="header__logo">
    <a href=""></a>
  </div>
  <nav>
    <ul>
      <li><a href="#">one</a></li>
      <li><a href="#">two</a></li>
      <li><a href="#">three</a></li>
      <li><a href="#">four</a></li>
    </ul>
  </nav>
  <div class="search"></div>
</header>

header {
  background: deepskyblue;
  display: flex;
  padding: 20px 0;
  .header__logo {
    background: aqua;
    flex: 20%;
    min-height: 140px;
  }
  nav {
    background: #111;
    flex: 78%;
    ul {
      list-style: none;
      margin: 0;
      background: aquamarine;
      display: flex;
      justify-content: flex-end;
            align-items: flex-end;
    }
    a {
      text-decoration: none;
      display: block;
      padding: 1em;
      color: white;
    }
  }
  .search {
    background: #fff;
    flex: 12%;
  }
}


推荐答案

你的代码,你实际上不是 nav 在底部放置 align-items:flex-end 。您将列表项放置在 ul 底部。

In your code, you're not actually placing the nav at the bottom with align-items:flex-end. You're placing the list items at the bottom of the ul.

除了 ul 容器没有添加高度,因此列表项不会到任何位置:

Except the ul container has no added height, so the list items don't go anywhere:

添加高度的演示

底部对齐 nav ,给它一个 align-self:flex-end ,因此它在更大的flex容器内对齐。

To bottom-align the nav, give it an align-self: flex-end, so it aligns within the larger flex container.

修改了小提琴

这篇关于嵌套的flexbox,align-items不flex-end的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆