html - 对齐 flexbox 内容器底部的元素

标签 html twitter-bootstrap css flexbox

Fiddle here.

我试图将白色插入符号 (^) 粘贴到 .section-1 的底部,水平居中但在最底部。如您所见,插入符本身位于 Bootstrap container-fluid 中,它本身位于 flex-box 中(通过 vertical-center 类应用)。

我尝试过使用边距和 bottom: 0; 等进行传统定位,但都无济于事。同样,flex-end 属性没有像我想象的那样工作。欢迎所有解决方案和建议,只要他们继续使用 flexbox。

最佳答案

您可以使用嵌套的 flex 容器来实现这一点。

HTML

<!-- one adjustment; add span -->
<div class="align-me-center"><span>Here is some centered text.</span></div>

CSS

/* ADJUSTMENT TO RULE */

.section-1 {
    min-height: 500px;
    background-color: #0099cc;
    height: 500px; /* necessary for child div with percentage height to work;
                      min-height overrides height, so no worries */
}

/* NEW RULES */

.container-fluid { 
    display: flex; /* establish nested flex container */
    flex-direction: column;
    height: 100%; /* use full height of container */
    justify-content: center; /* position flex items at opposite end of container */
}

.align-me-center { 
    display: flex; /* nested flex container to center flex item (span) */
    align-items: center;
    justify-content: center; 
    height: 100%;
}

演示:http://jsfiddle.net/b26j5m6t/3/

关于html - 对齐 flexbox 内容器底部的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32979328/

相关文章:

html - 使可滚动的 div 成为 100% 的内容,而不延伸到底部

javascript - 滚动 div 时 react

css - 响应式背景不会在手机中填满屏幕

css - 如果 bootstrap 3 grid 的宽度为 1500px,应该设置什么断点?

javascript - Isotope JS 选项卡在第一次加载时显示所有内容

javascript - 使用javascript重定向到同一文件夹中的另一个页面

html - 如何在 Blazor 中更改 CSS 或 "body"元素的类

javascript - 即使其他 JS 工作正常,Twitter 的 Bootstrap Popover : Won't work,

html - Bootstrap - 3 列全响应全高介绍页面

javascript - li类只能和css互换吗