您可以使用嵌套的柔性容器做到這一點。
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%;
}
DEMO:http://jsfiddle.net/b26j5m6t/3/
這是接近的,但我還是想插入符號上方的文字垂直居中。 – daveycroqet
再一次調整。完成。 http://jsfiddle.net/b26j5m6t/3/ –
這正是我想要做的。完善! – daveycroqet