2014-04-12 202 views
-1

過去兩天,我一直在琢磨着我的想法。基本上,我正在創建一個頁面佈局,其中第一個塊佔用屏幕的寬度和高度,第二個塊需要是相對的。Div採用屏幕寬度和高度

實施例:http://www.shegy.nazwa.pl/themeforest/exit/normal/

<body> 

<div id = "block1"> 
This is block 1 taking 100% width and height of screen. 
</div> 

<div id="block2"> 
Block 2 is relative to block 1 
</div> 

</body> 
+0

怎麼樣使用'寬度:100vw;身高:100vh'? – Terry

回答

1

訣竅是添加height: 100%;margin: 0;到主體/ HTML。然後它創造奇蹟:)。

HTML:

<div id="box1">HELLO HELLO THIS IS RED BOX, ARE YOU HEARING ME BLUE?</div> 
<div id="box2">YES, RED, I'VE GOT YOU LOUD AND CLEAR. OVER. <div> 

CSS:

html, body { 
    height: 100%; 
    margin: 0; 
} 
#box1 { 
    min-height: 100%; 
    min-width: 100%; 
    color: white; 
    background-color: red; 
} 

#box2 { 
    min-height: 100%; 
    min-width: 100%; 
    color: white; 
    background-color: blue; 
} 

FIDDLE:

http://jsfiddle.net/ewzLM/1/

+0

不,這將是一個完美的例子: http://www.shegy.nazwa.pl/themeforest/exit/normal/ – sidegeeks

+0

@Riqwan所以下一頁也是100%100%? – Shahar

+0

只有寬度是100%。它本身不是頁面,但是。 – sidegeeks