带有底部锚定元素的 CSS flexbox 垂直堆栈

标签 css flexbox

如何使用 flexbox 布局创建一个垂直堆栈(列)的 div,其中一个 div 锚定到容器底部?

|--------|
|  div1  |
|  div2  |
|  div3  |
|        |
|        |
|        |
| fixed1 |
|--------|

例如,在这个 fiddle我希望元素 1、2 和 3 水平居中并垂直对齐到顶部,固定元素水平居中并垂直对齐到底部。

HTML
<div class="container">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="fixed">Fixed Item</div>
</div>

CSS
html, body {
    min-height: 100%;
    height: 100%;
}

.container {
    height: 50%;
    background: #EEE;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    align-content: center;
}

.fixed {
    align-self: flex-end;
}

最佳答案

这有点棘手,因为似乎 align-self仅适用于 flex-direction:row .

我确实设法通过包装你的.fixed让它“有点”工作。带有另一个 flexbox 的元素。

看到这个fiddle .

关于带有底部锚定元素的 CSS flexbox 垂直堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29976300/

相关文章:

html - 如何在wordpress wp_nav函数中包装子菜单

html - Joomla 3.x : Limit a module's size

html - 使用 CSS flex 的两个全高页面

javascript - 如何使用 jQuery 切换 flexbox 样式弹出窗口的可见性?

html - Bootstrap + Flexbox 动态高度

javascript - 如何仅在 JS/jQuery 中处理冲突?

javascript - 在 WEB 应用程序中隐藏已选定选项卡的超链接按钮

css - 如何消除 child 之间的垂直差距

css - 响应式网站在手机上以全宽显示(但在模拟手机上不显示)

css - Angular 响应式表单模板