簡體   English   中英

如果網頁上沒有內容而不是單個標題,如何將文本保持在頁腳附近

[英]How to keep the text near the footer if there is no content on the web page other then a single heading

我試圖讓我的 h1 保持在頁腳附近而不在頁眉上使用 margin-bottom 以便我的文本將保持在頁腳附近我想要這樣的東西在此處輸入圖片描述

我嘗試過的解決方案是給頁眉提供 margin-bottom:515px 以便它保持在底部,但如果我知道任何更好的方法來實現這件事,我將不勝感激

由於重疊問題,無法推薦絕對位置。 Flex 會變魔術。

 body, html { margin: 0; } .header { align-items: flex-end; background-color: red; display: flex; height: calc(100vh - 100px); } h1 { margin: 0 0 50px; } .footer { align-items: center; background-color: blue; color: white; display: flex; height: 100px; width: 100% } p { margin: 0; }
 <div class="header"> <h1>H1 goes here</h1> </div> <div class="footer"> <p>footer goes here</p> </div>

您可以對 h1 使用絕對定位:

position: absolute;
left: 0px; 
bottom: 0px;

或者制作一些 div 來保存頁面的結構:

//css
#header {
     height: 'headerHeight'px;
}
#content {
     height: Calc(100% - 'headerHeight'px - 'footerHeight'px);
}
#footer {
     height: 'footerHeight'px;
}
//html
<body>
    <div id="header"></div>
    <div id="content"></div>
    <div id "footer">your H1</div>
</body>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM