正如標題所示,我正在嘗試將我的頁腳中的文本對齊到水平中心並與底部對齊。我已經嘗試將父div設置爲relative,p元素設置爲absolute,然後bottom:0;/vertical-align:bottom;但不起作用。頁腳中的文本不會與底部中心對齊
發生什麼是文本向上移動到上面的div並不再是水平居中。
/*Section3*/
#section3 {
height: 50%;
background: #6ed3cf;
text-align: center;
padding: 0 0 0.5em;
height: 20em;
}
#section3 h2 {
font-size: 2em;
font-weight: 200;
}
#section3 i {
padding: 0.5em;
color: black;
}
/*Footer*/
#footer {
background:#fff;
color: black;
height: 10%;
font-family: 'Open Sans', sans-serif;
position: relative;
display: table;
}
#footer p {
font-size: 0.7em;
text-align: center;
position: absolute;
bottom: 0;
vertical-align: bottom;
}
<div id="section3" style="display:flex;justify-content:center;align-items:center;">
\t <div>
\t \t <h2>header</h2> \t
\t \t <div class="container">
\t \t \t <div class="row">
\t \t \t \t <div class="col-md-6 col-md-offset-3">
\t \t \t \t \t <p>blablablablablablablablablablablablablablablablablablablablabla</p>
\t \t \t \t \t <a href="#"><i class="fa fa-envelope fa-2x" aria-hidden="true"></i></a> \t
\t \t \t \t \t <a href="#"><i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i \t \t \t ></a> \t \t
\t \t \t \t </div>
\t \t \t </div>
\t \t </div>
\t </div>
</div>
<!-- Footer -->
<div id="footer">
\t <div class="container">
\t \t <div class="row">
\t \t \t <div class="col-md-4 col-md-offset-4">
\t \t \t \t <p>text</p> \t
\t \t \t </div>
\t \t </div>
\t </div>
</div>
:在頁腳table'?要麼刪除這個屬性,要麼使用'width:100%'。從'p'中刪除不必要的'position:absolute'。 –
當你在一個元素上應用'display:table'時,它的寬度取決於裏面的內容,除非'width'屬性或通過css顯式應用。 –