2016-07-30 106 views
-1

我想填充整個自由底部空間(白色)在寬度大於內容的情況下顯示的情況下如何設置css3樣式來執行此操作?填充整個底部的頁腳

enter image description here

CSS:

.footer { 
    background-color: #FFFFFF; 
    line-height: 20px; 
    /*border-top: 1px solid #DDDDDD;*/ 
    overflow: hidden; 
} 
.footer .copyright { 
    font-family:Lato; 
    color: #f6f6f6; 
    padding: 10px 15px; 
    margin: 15px 3px; 
    line-height: 20px; 
    text-align: center; 
    font-size:0.9em; 
    font-weight:400; 
} 
.footer-color-black, 
.footer-transparent { 
    background-color: #595324; 
    color: #DDDDDD; 
    text-align:center; 
} 

https://jsfiddle.net/3re9wbr2/1/

+0

你的代碼在哪裏?放在jsfiddle或這裏 –

+0

你嘗試了什麼? – Utkanos

+0

@Sumitpatel https://jsfiddle.net/3re9wbr2/1/ – test

回答

1

首先,加入margin: 0到HTML/body標籤會給你這個

html, 
 
body { 
 
    margin: 0; 
 
} 
 

 
.footer { 
 
    background-color: #FFFFFF; 
 
    line-height: 20px; 
 
    /*border-top: 1px solid #DDDDDD;*/ 
 
    overflow: hidden; 
 
} 
 

 
.footer .copyright { 
 
    font-family: Lato; 
 
    color: #f6f6f6; 
 
    padding: 10px 15px; 
 
    margin: 15px 3px; 
 
    line-height: 20px; 
 
    text-align: center; 
 
    font-size: 0.9em; 
 
    font-weight: 400; 
 
} 
 

 
.footer-color-black, 
 
.footer-transparent { 
 
    background-color: #595324; 
 
    color: #DDDDDD; 
 
    text-align: center; 
 
}
<div class="section"> 
 
    <div class="container"> 
 
    <div class="title-area"> 
 
     <div class="gallerygrid"> 
 
     <h5>content ldosalodaslodlsoalodslaodasol</h5> 
 
     <h5>content ldosalodaslodlsoalodslaodasol</h5> 
 
     </div> 
 
    </div> 
 

 
    </div> 
 
</div> 
 

 
<footer class="footer footer-big footer-color-black" data-color="black"> 
 
    <div class="copyright"> 
 
    © 
 
    <script> 
 
     document.write(new Date().getFullYear()) 
 
    </script> · Lorem Ipsum · All Copyright reserved 
 
    </div> 
 
</footer>

其次,使用display: flexmin-width: 100vh添加wrapper並給予.footerflex: 1會給你這個

html, 
 
body { 
 
    margin: 0; 
 
} 
 

 
.wrapper { 
 
    min-height: 100vh; 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 

 
.section { 
 
} 
 

 
.footer { 
 
    flex: 1; 
 
    background-color: #FFFFFF; 
 
    line-height: 20px; 
 
    /*border-top: 1px solid #DDDDDD;*/ 
 
    overflow: hidden; 
 
} 
 
.footer .copyright { 
 
    font-family: Lato; 
 
    color: #f6f6f6; 
 
    padding: 10px 15px; 
 
    margin: 15px 3px; 
 
    line-height: 20px; 
 
    text-align: center; 
 
    font-size: 0.9em; 
 
    font-weight: 400; 
 
} 
 
.footer-color-black, 
 
.footer-transparent { 
 
    background-color: #595324; 
 
    color: #DDDDDD; 
 
    text-align: center; 
 
}
<div class="wrapper"> 
 
    <div class="section"> 
 
    <div class="container"> 
 
     <div class="title-area"> 
 
     <div class="gallerygrid"> 
 
      <h5>content ldosalodaslodlsoalodslaodasol</h5> 
 
      <h5>content ldosalodaslodlsoalodslaodasol</h5> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 

 
    <footer class="footer footer-big footer-color-black" data-color="black"> 
 
    <div class="copyright"> 
 
     © 
 
     <script> 
 
     document.write(new Date().getFullYear()) 
 

 
     </script> · Lorem Ipsum · All Copyright reserved 
 
    </div> 
 
    </footer> 
 
</div>

+0

這是粘性的頁腳。我不確定我如何描述我的問題。例如:中間屏幕和底部的頁腳應該用頁腳的顏色填充。 – test

+0

@test更新我的2:nd樣本,更好? – LGSon

+0

好多了!這就是我想要的。謝謝 – test

0

聽起來像是你想有一個粘頁腳。

Ryan Fait's method效果很好。

+0

不幸的是,這不是我想要的。也許最簡單的方法將添加div(身體的第二背景) – test