2016-07-28 36 views
0

我無法創建靜止頁面底部的靜態頁腳。我嘗試過實現粘性頁腳,但是當我嘗試時,沒有明顯的區別。目前,頁腳與頁面一起滾動。我不知道是否是因爲我的HTML或其他CSS設置,或者我只是不知道。如何在CSS中創建靜態頁腳?

這裏是我的代碼和滾動頁腳的例子:https://codepen.io/bobblyhead/pen/yJEdzj

html, body{ 
    margin: 0px; 
    padding: 0px; 
    min-height: 100%; 
    margin-bottom: 100px; 
    clear: both; 
    position: relative; 
} 

.footer{ 
    position: fixed; 
    margin-bottom: 0px; 
    right: 0; 
    bottom: 0; 
    left: 0; 
    width: 100%; 
    background-color: #212121; 
    padding: 10px; 
    color: white; 
    font-size: .81em; 
} 
footer div:first-child{ 
    margin-bottom: 5px; 
} 
footer .glyphicon{ 
    margin-right: 5px; 
} 
footer a:link, footer a:visited, footer a:hover, footer a:active{ 
    color: white; 
} 
footer .contacts{ 
    text-align: left; 
} 

GettingStarted.html:

<html> 
<head> 
    <!--[if lt IE 9]> 
     <script src="dist/html5shiv.js"></script> 
    <![endif]--> 
    <link rel="stylesheet" href="login.css"> 
    <link rel="stylesheet" href="header.css"> 
    <link rel="stylesheet" href="footer.css"> 

    <script src="https://use.fontawesome.com/fae6c977ea.js"></script> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" /> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 

</head> 
<body> 
<!--Content--> 
<div class = "wrapper"> 
    <div class="container"> 
    <h1> Getting Started </h1> 
    </div> 
    <div class=container> 
     <div id="sysReq"><h3> System Requirements </h3> 
      <div class= "col-md-12"> 
       <p> This is a paragraph about system requirements.</p> 
      </div> 
     </div> 
     <div id="install"><h3> Installation </h3> 
      <div class= "col-md-12"> 
       <p> This is a paragraph about installation.</p> 
      </div> 
     </div> 
     <div id="sandbox"><h3> Try it now - API Sandbox </h3>   
      <div class= "col-md-12"> 
       <p> SANDBOX! </p> 
      </div> 
     </div> 
    </div> 
</div> 




<!-- FOOTER --> 
    <div class="footer"> 
     <div class="siteContent" style="padding-top:10px;"> 

      <div style="width:42%; float:left; margin-left: 15px;"> 
       <span style="font-size:75%;">&copy;Copyright 2016.</span> 
       <span style="font-size:75%;">Test.</span> 
       <br> 
      </div> 

      <div style="width:22%; float:left; margin-left: 10px;"> 
       <span class="glyphicon glyphicon-envelope"></span>&nbsp;&nbsp;<a href="mailto:[email protected]?Subject=Question" target="_top">[email protected]</a><br> 
       <span class="glyphicon glyphicon-phone-alt"></span>&nbsp;&nbsp;Americas&nbsp;&nbsp;&nbsp;&nbsp;+x.xxx.xxx.xxxx<br> 
       <span class="glyphicon glyphicon-phone-alt"></span>&nbsp;&nbsp;EMEA&nbsp;&nbsp;&nbsp;&nbsp;+xx.xx.xxxx.xxxx 
      </div> 

      <div style="width:22%; float:left; margin-left: 10px;"> 
       <br> 
       <span class="glyphicon glyphicon-phone-alt"></span>&nbsp;&nbsp;Asia&nbsp;&nbsp;&nbsp;&nbsp;+xxx-xxxx-xxxx<br> 
       <span class="glyphicon glyphicon-phone-alt"></span>&nbsp;&nbsp;Japan&nbsp;&nbsp;&nbsp;&nbsp;+xx-x-xxxx-xxxx 
      </div> 
     </div> 
    </div> 

    <div class="modal fade" id="selectModal" tabindex="-1" role="dialog" aria-labelledby="Select Columns" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"></div></div></div> 
    <div class="modal fade" id="pdfmodal" tabindex="-1" role="dialog"><div class="modal-dialog"><div class="modal-content"></div></div></div> 
    <div id="username" class="hidden"></div> 

    </div> 

</body> 
</html> 

UPDATE:

我改變了position: absolute;,並設置margin-bottom: -140px;它似乎解決了這個特定頁面上的問題。

但是,在內容較少的頁面上,頁腳和底部之間存在空格。它看起來像this

+0

如果'

'元素具有'fixed'定位,那麼是否將'html'和'body'定位從'relative'改爲'static'有幫助? –

+0

@NateWhittaker我試過了,似乎沒有任何改變。 –

+0

如果你谷歌這個問題有數百個有效的答案。 – Martin

回答

0

嘗試使用

.footer { 
position:absolute; 
bottom:0px; 
} 

並在.wrapper中使用最小高度

+0

謝謝!它不會隨頁面一起滾動,但它覆蓋了一些內容並且不會粘在最下面。 https://i.gyazo.com/15fd41c7497109f3ccb73aaa7f83a5da.png –

+0

如果你也可以在包裝中顯示'min-height'來完成這個答案,那將是非常有用的。 – Martin

0

如果我知道你想什麼(即住在很短的頁面底部的頁腳,但它成長),你可以用Flexbox的做到這一點:

body { 
 
\t margin: 0; 
 
\t display: flex; 
 
\t flex-direction: column; 
 
\t min-height: 100vh; 
 
} 
 

 
.site-content { 
 
\t flex: 1; 
 
}
<div class="page"> 
 
    <header class="site-header"></header> 
 

 
    <main class="site-content"></main> 
 

 
    <footer class="site-footer"></footer> 
 
</div>

這裏有一些更多的解決方案(法國):https://www.emmanuelbeziat.com/blog/un-site-qui-prend-toute-la-hauteur-disponible/

1

您可以從位置:固定位置:相對位置修改頁腳樣式。它會解決你的問題,只是增加填充感覺很好。

相關問題