2017-02-20 28 views
2

頁腳不會留在我的

html, body { 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t margin: 0px; 
 
\t padding: 0px; 
 
\t background-image: url(../images/bg.jpg); 
 
\t background-attachment: fixed; 
 
\t background-position: center; 
 
\t background-repeat: no-repeat; 
 
\t background-size: cover; 
 
\t min-height: 100%; 
 
} 
 

 

 
/*----------------------Header Styling------------------------------------*/ 
 

 
header { 
 
\t background-color: white; 
 
\t border-bottom-style: solid; 
 
\t overflow: auto; 
 
\t height: 200px; 
 
\t font-family: "Freehand521 BT", Arial, Sans-serif; 
 
} 
 

 
header p { 
 
\t font-family: "Freehand521 BT", Arial, Sans-serif; 
 
\t margin: 20px 0px 0px 20px; 
 
\t font-size: 60px; 
 

 
} 
 

 
header img { 
 
\t float: right; 
 
\t border-left: solid; 
 
} 
 

 
/*-------------------------------Main Nav Styling--------------------------------*/ 
 

 
#mainlinks { 
 
\t margin-top: 60px; 
 
} 
 

 
#mainlinks ul { 
 
\t margin-bottom: 0px; 
 
} 
 

 
#mainlinks a { 
 
\t list-style-type: none; 
 
\t text-decoration: none; 
 
\t color: black; 
 
\t margin-right: 90px; 
 
\t margin-left: -10px; 
 
\t font-size: 25px; 
 
} 
 

 
#mainlinks li { 
 
\t display: inline; 
 
\t padding-right: 5px; 
 
} 
 

 
/*----------------------------------Secondary Nav Styling----------------------------------------------------*/ 
 

 

 
.secondlinks li { 
 
\t display: inline; 
 
\t list-style-type: none; 
 
} 
 

 
.secondlinks ul { 
 
\t padding-left: 0px; 
 
} 
 

 

 
/*-------------------------------------Main Content Styling--------------------------------------------------------*/ 
 

 
#contentwrap { 
 
\t background-color: rgba(231, 231, 231, .7); 
 
\t border-style: solid; 
 
\t border-radius: 10px; 
 
\t margin-top: 30px; 
 
\t margin-left: 20px; 
 
\t margin-right: 20px; 
 
\t padding: 15px; 
 
\t font-family: "Freehand521 BT", Arial, Sans-serif; 
 
\t font-size: 17px; 
 

 
} 
 

 
#contentwrap img { 
 
\t border-style: solid; 
 

 
} 
 
/*-------------------------------------------Footer Styling------------------------------------------------------*/ 
 

 
footer { 
 
\t background-color: #fff; 
 
\t border-top-style: solid; 
 
\t margin-top: 20px; 
 
\t width: 100%; 
 
\t height: 130px; 
 
\t font-family: "Freehand521 BT", Arial, Sans-serif; 
 
\t font-size: 15px; 
 
} 
 

 
#footernav { 
 
\t float: right; 
 
} 
 

 
#footernav li { 
 
\t display: inline; 
 
} 
 

 
#footernav a { 
 
\t text-decoration: none; 
 
\t margin-right: 30px; 
 

 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>Defenders Of The Stars!--The Official Sailor Moon Fanpage!</title> 
 
\t <meta charset="utf-8"> 
 
\t <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
\t <link rel="icon" type="image/png" href="images/SM.ico"> 
 
\t <link rel="stylesheet" type="text/css" href="style/style.css"> 
 
\t <link rel="stylesheet" href="style/normalize.css"> 
 
</head> 
 
<body> 
 
\t <header> 
 
\t \t <img src="images/HeaderSilouette.png" alt="Defenders Of The Stars Header" width="200" height="200"> 
 
\t \t <p>Defenders of the stars!</p> 
 
\t \t <nav id="mainlinks"> 
 
\t \t \t <ul> 
 
\t \t \t \t <li><a href="main.html">Home</a></li> 
 
\t \t \t \t <li><a href="ss.html">Sailor Senshi</a></li> 
 
\t \t \t \t <li><a href="villains.html">Villains</a></li> 
 
\t \t \t </ul> 
 
\t \t </nav> 
 
\t </header> 
 
\t <div id="contentwrap"> 
 
\t \t <h1> Welcome Fans!</h1> 
 
\t \t <p>Welcome to the Official Sailor Moon Fanpage! Here you will find a lot of information about the Sailor Moon Universe! Including Characters and villains alike, As well as an overview of the story so far. We will also keep this Page updated with the latest happenings in the world of Sailor Moon!</p> 
 
\t \t <p><u>July 5 2014</u> - New Sailor Moon Anime, Sailor Moon Crystal is released!</p> 
 
\t </div> 
 
\t <footer> 
 
\t \t <p id ="copyright">&copy; Copyright 2016 Jorge Goris.<br />Designed and developed by Jorge Goris.</p> 
 
\t \t <nav id="footernav"> 
 
\t \t \t <ul> 
 
\t \t \t \t <li><a href="main.html">Home</a></li> 
 
\t \t \t \t <li><a href="ss.html">Sailor Senshi</a></li> 
 
\t \t \t \t <li><a href="villains.html">Villains</a></li> 
 
\t \t \t </ul> 
 
\t \t </nav> 
 
\t </footer> 
 
</body> 
 
</html>

這裏是我的代碼片段的一個網頁的底部。在我的主頁中,我一直在腳下留下一點空間。設置高度似乎適用於其他頁面,因爲它們有很多內容。但是,我的主頁並不是這樣,頁腳並沒有完全消失。我已經嘗試了很多不同的方式來獲得這個正確的,我似乎無法做到這一點。我究竟做錯了什麼?

回答

0

一下添加到#contentwrap

padding-bottom: 130px; 
min-height: 100%; 

而且這footer

position: relative; 
margin-top: -130px; 
clear: both; 

如果以後更改頁腳的高度,改變上述相應的值。 Working codepen

+1

非常感謝這個工作!去保存這段代碼供以後使用,因爲這個頁腳的情況一直是我試圖創建的所有頁面的麻煩。再次感謝! – Jorge

+0

現在,我從頂部和內容的頭部有一些空間。我如何在我的內容和頁腳之間創建相同數量的空間? – Jorge

+0

@你的意思是說,讓內容底部有一個圓形的邊框,在頁腳的上方(如頂部)? – Michael

1

嘗試使用這種外頁腳元素:

position: absolute; 
bottom: 0; 

您可以使用填充,或者繼續使用bottom屬性進一步調整位置。如果您將其置於0以上(即「5px」),則在底部屬性中輸入的數字應該包括px。該值是來自/底部的像素,因此添加更多將會推動它。

+1

這是不正確的,因爲如果內容大於屏幕,並且用戶滾動。頁腳將與內容滾動 –

0

只要到頁腳造型和刪除height屬性:

高度:130px;

這將允許頁腳調整它自己的高度。

+1

這是不正確的,因爲OP正在尋找將頁腳放置在屏幕的底部, –

1

應用此操作將頁腳固定到底部, 如果此行爲僅適用於一頁,請務必使用唯一的類。

footer { 
    position: fixed; 
    bottom: 0; 
} 

如果含量大於可用空間更大,你還可以添加

body { 
    padding-bottom: 130px; // the height of the footer 
} 

或者,你應該探索利用Flexbox,就與一些後備一起建立自己的UI。 這裏是一個很好的文章https://css-tricks.com/snippets/css/a-guide-to-flexbox/

+0

此代碼適用於將頁腳固定到屏幕底部,但OP希望將其置於**文檔**的底部,同時在內容和頁腳之間添加空格以顯示較大的屏幕,以便在頁腳底部和屏幕底部之間不留空白。 – Michael