簡體   English   中英

固定的頁眉和頁腳以及100%的高度含量

[英]Fixed header and footer and 100% height content

我正在嘗試創建一個具有固定頁眉和頁腳的網站,然后在其中一個內容div填充窗口(如高度100%),而無需將頁腳推到折疊以下。

我創建了這個JSFiddle來說明我正在嘗試做的事情: http : //jsfiddle.net/CZFBE/

<body>
<header>
    <nav>Menu</nav>
</header>
<section>
    <div class="hero">Hello World</div>
</section>
<footer>
    Copyright lol
</footer>
</body>

我需要section元素來填充空白屏幕空間。 這是可能嗎? 我已經嘗試解決這一問題了幾天了,感謝您的幫助或想法!

提前致謝!

我已經在JSFiddle中更新了您的代碼: http : //jsfiddle.net/CZFBE/2/

html {
    height: 100%;
}
body {
    height:100%;
    min-height: 100%;
}
header {
    width:100%;
    top:0px;
    left:0px;
    background: grey;
    height: 4em;
    position:absolute;
}
section {
    height: 100%;
    background: lightgrey;
}
.hero {
    text-align: center;
}
footer {
    width:100%;
    bottom:0px;
    left:0px;
    position:absolute;
    background: grey;
    height: 4em;
}

嘗試類似的方法,它對我有用:

header, footer, section{
    position: absolute;
    width: 100%;
    left: 0;
}
header, footer{
    height: 10%;
}
header{
    top: 0;
}
footer{
    bottom: 0;
}
section{
    height: 80%;
    top: 10%;
    overflow: auto;
}

頁眉和頁腳都占用10%的空間,並且不會移動,部分則占用其余部分並滾動。

看看這個JSFiddle

如果您指定bodyhtml height:100%

您也可以通過將section height:100%

鑒於您需要固定的頁腳+頁眉,這就是我想出的

body,html{
    height: 100%;
    margin: 0 auto;
}
header{
    background: grey;
    height: 4em;
    position: fixed;
    top: 0;
    width: 100%;
}
section{
    background: lightgrey;
    height: 100%;
    margin-top:4em;
}
.hero{
    text-align: center;
}
footer{
    background: grey;
    height: 4em;
    position: fixed;
    bottom: 0;
    width: 100%;
}

暫無
暫無

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

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