我试图将白色插入符号(^)粘贴到.section-1
的底部,水平居中但位于最底部。如您所见,插入符本身位于Bootstrap container-fluid
中,它本身位于弹性框内(通过vertical-center
类应用)。
我尝试使用边距和bottom: 0;
等传统定位无济于事。同样,flex-end
属性并没有像我想象的那样工作。欢迎所有解决方案和建议,只要他们继续使用flexbox。
答案 0 :(得分:1)
您可以使用嵌套的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%;
}