2013-09-22 36 views
-3

我想構建html5頁面以使用瀏覽器窗口的可用高度,但不使用寬度。我想包含標題,邊欄,頁腳和內容<div>標籤內的容器<div>標籤(或可能是嵌套容器<div>標籤)與固定寬度。如何使用div標籤爲html創建表格式佈局5

我已經在網上進行了廣泛的搜索,但實際上沒有任何反應。

佈局應在圖像中顯示:

Layout image

我在這裏不加<風格>建議,而不是挑起錯誤的答案。

+1

這是StackOverflow的不是如何工作的伴侶。嘗試編寫HTML和CSS。如果您遇到任何特定問題,請在此處發帖,您將得到更好的答覆/幫助。 – Harry

+1

歡迎來到Stack Overflow!看起來你希望我們爲你寫一些代碼。儘管許多用戶願意爲遇險的編碼人員編寫代碼,但他們通常只在海報已嘗試自行解決問題時才提供幫助。證明這一努力的一個好方法是包含迄今爲止編寫的代碼,示例輸入(如果有的話),期望的輸出和實際獲得的輸出(控制檯輸出,堆棧跟蹤,編譯器錯誤 - 無論是適用)。您提供的細節越多,您可能收到的答案越多 – dhein

回答

3

Working Fiddle

所以,基本上我這樣做是爲了提高自己。我不認爲它適合你複製整個事情。 閱讀它,並嘗試從頭開始。

HTML:

<div id="Container"> 
    <div id="Header"></div> 
    <div id="Page"> 
     <div id="SideBar"></div> 
     <div id="Content"></div> 
    </div> 
    <div id="Footer"></div> 
</div> 

CSS:

* 
{ 
    padding: 0; 
    margin: 0; 
    -moz-box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    box-sizing: border-box; 
} 

html, body 
{ 
    height: 100%; 
} 

body 
{ 
    padding: 20px 0; 
    background-color: cadetblue; 
} 

#Container 
{ 
    width: 70%; /* or: any fixed width that fits you */ 
    height: 100%; 
    margin: 0 auto; 
    padding: 20px 0; 
    background-color: white; 
} 

#Header 
{ 
    height: 75px; /* or: any fixed height that fits you */ 
    background-color: orange; 
    margin: 0 20px; 
} 
#Page 
{ 
    height: calc(100% - 125px); /* 100% - (Header.height + Footer.height) */ 
    width: 100%; 
    display: table; 
    border-spacing: 20px; 
} 
#SideBar 
{ 
    display: table-cell; 
    background-color: yellow; 
    width: 20%; /* or: any fixed width that fits you */ 
} 
#Content 
{ 
    display: table-cell; 
    background-color: greenyellow; 
} 

#Footer 
{ 
    height: 50px; /* or: any fixed height that fits you */ 
    background-color: lightblue; 
    margin: 0 20px; 
} 
+0

非常感謝您。這似乎工作。我以前曾嘗試調整這裏的回覆[link](http://stackoverflow.com/questions/15923019/how-to-make-a-div-fill-the-remaning-vertical-space-using-css)但它不起作用。 – Cush

+0

@Cush不要忘記標記答案已被接受。 – avrahamcool

+0

我喜歡這些顏色。 – Mikhail