我想根據瀏覽器大小製作正確縮放的網站。我知道通常需要將所有寬度和高度設置爲100%,但是我不知道如何設置頁眉和頁腳的最小高度和最小高度。學校徽標將顯示在標題太小時無法閱讀,側邊欄中顯示Google日曆。有固定位置和相對位置使網頁佈局發生問題
我想要做的就是設置它,使標題和副標題(深藍色和深灰色條)被設置爲固定位置。側邊欄(黑色欄)設置爲固定,以及頁腳(淺灰色)。內容部分(白色框)我想成爲包含所有新聞和更新的唯一可滾動部分。無論我如何設置,總是不適當地移動。
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Website Layout Test
</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen">
</head>
<body>
<div id="header-container">
<div id="header"></div>
<div id="sub-header"></div>
</div>
<div id="content-container">
<div id="content"></div>
<div id="sidebar"></div>
</div>
<div id="footer"></div>
</body>
</html>
和CSS
#header-container{
width:100%;
height:96px;
position:relative;
}
#header{
width:100%;
background-color:#013066;
height:60px;
position:fixed;
}
#sub-header{
width:100%;
background-color:grey;
margin-top:60px;
height:36px;
position:fixed;
}
#content-container{
width:100%;
height:100%;
position:relative;
padding-bottom:55px;
background-color:pink;
}
#content{
background-color:white;
float:left;
height:100%;
width:100%;
position:relative;
}
#sidebar{
width:315px;
height:100%;
background-color:black;
position:fixed;
right:0px;
}
#footer{
position:fixed;
bottom:0px;
height:40px;
width:100%;
background-color:#f6f6f6;
}
謝謝,令人驚訝的工作完美!我猜測,這與內容容器在標題容器上滾動有關,而不是後者滾動。 –
當html中的兩個元素重疊時,則根據元素的z-index將其隱藏在另一個下面。因爲我已經將headcontainer的z-index設置爲10,它總是會在contentconatiner之上。 10號井是我用過的一個隨機值。你可以使用任何其他更高的價值。具有最高Z指數的元素保持在頂部。良好運氣! –