2014-09-10 118 views
0

我已經制作了一個容器並將其設置爲中間寬度邊距:0 auto,但是我遇到了一個問題,就是我想使某些內容寬度適合窗口寬度爲100%寬度?如何使Div展開寬度爲100%

有什麼辦法可以做到嗎?

如果我使用填充:0 400px和margn-left:-200?

這是我的工作代碼。

CSS

html, body {width:100%; height:100%; background:lightblue} 
* { margin:0; padding:0} 
#container { 
    width:1024px; 
    min-height:100%; 
    background:red; 
    margin:0 auto; 
    position:relative; 
} 

header { 
    width:100%; 
    height:80px; 
    background:skyblue; 
} 

header ul {list-style-type:none; float:right} 
header ul li {display:inline-block; padding: 10px; 20px;} 

#content { 
    width:100%; 
    height:200px; 
    background:yellow; 
    padding:0 300px; 
    margin-left:-200px; 
} 

http://codepen.io/jaminpie/pen/CHrIf

Thansk用於幫助..

回答

0

對於具有100%的寬度窗口寬度

DEMO

使用1/100th of the width of the viewport.

width:100vw; 

box-sizing

enter image description here

全碼:

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

html, body {width:100vw; height:100vh; background:lightblue} 

#container { 
    width:100%; 
    min-height:100%; 

    background:red; 
    margin:0 auto; 
    position:relative; 
} 

header { 
    width:100%; 
    height:80px; 
    background:skyblue; 
} 

header ul {list-style-type:none; float:right} 
header ul li {display:inline-block; padding: 10px; 20px;} 

#content { 
    width:100vw; 
    height:200px; 
    background:yellow; 
    padding:0 300px; 
    margin-left:-200px; 
} 
+0

但仍需要保證金左:-200px吧?? – jamjamlong 2014-09-10 17:21:58

+0

不,你不需要它,如果你的計劃是顯示完整的div它之前有 – 2014-09-10 17:23:03

0

移動內容的div容器的外面,然後把它從頂部絕對定位80px以便它正好落在標題下方。

#content { 
    width:100%; 
    height:200px; 
    background:yellow; 
    padding:0 300px; 
    position:absolute; 
    top:80px; 
} 

Updated Pen

+0

嗨感謝您的幫助和代碼,但如果我有一個粘腳。如果我使用絕對頁腳不會幫助我推倒底部? – jamjamlong 2014-09-10 17:04:13

+0

只需在頁腳上執行'position:absolute;'和'bottom:0;'。 – APAD1 2014-09-10 17:23:04