简体   繁体   English

在包含div的底部对齐Flex导航项

[英]Align flex nav items at the bottom of a containing div

I am trying to align 3 tabbed items (using ul flexbox items) on top of an image at the bottom using a containing div, but for the life of me, I can't get them all to stay within the containing div. 我正在尝试使用包含div在底部的图像对齐3个选项卡式项目(使用ul flexbox项),但是为了我的生命,我无法让它们全部都包含在包含div中。

If I use position:absolute; bottom:0; 如果我使用position:absolute; bottom:0; position:absolute; bottom:0; It makes everything worse, so I am a bit stuck how to fix it! 它使一切变得更糟,所以我有点不知如何解决! I also tried margin-top:auto on the <li> , and that didn't help either. 我还尝试了<li>上的margin-top:auto ,但这也没有帮助。

Here is the JSFiddle: link or code directly: 这是JSFiddle:直接链接或代码:

<div class="container">
  <img src="http://via.placeholder.com/400x400">
  <ul class=flextabs>
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a></li>
  </ul>
</div>

.container {
  width: 400px;
  height: 400px;
  background: blue;
  text-align: center;
  border:solid;
}

ul.flextabs {
    margin:0;
    padding:0;
    list-style:none;
    display:flex;
}
li {
    display:flex;
    flex-direction:column;
    flex: 1 0 auto;
    border:1px solid #000;
}
a {
    text-decoration:none;
    color:#000;
    background:red;
    padding:5px;
}
a:hover{background:orange;}

This is the current result: 这是当前结果:

当前

vs What I would like to achieve (above image edited) vs我想要达到的目标(图片编辑后)

试图得到

I would use position: absolute; 我会使用position: absolute; on the ul to place it at the bottom of the container, and apply flex to it - not to the container or to the li s. ul将其放置在容器的底部,并应用flex的-不给容器或到li秒。 And I also changed and added some other details: 我还更改并添加了其他一些细节:

 .container { width: 400px; height: 400px; background: blue; text-align: center; border: 2px solid black; position: relative; } ul.flextabs { position: absolute; bottom: 0; width: 100%; margin: 0; padding: 0; list-style: none; display: flex; } li { display: inline-block; width: 33.33%; border: 1px solid #000; } a { text-decoration: none; color: #000; background: red; padding: 5px; display: block; } a:hover { background: orange; } 
 <div class="container"> <img src="http://via.placeholder.com/400x400"> <ul class=flextabs> <li><a href="#">Testing</a></li> <li><a href="#">Testing</a></li> <li><a href="#">Testing</a></li> </ul> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM