2016-09-09 19 views
1

我正在嘗試創建一個適用於手機的簡單單頁網站。理想情況下,我希望網站的每個部分都達到瀏覽器高度的100%。這是網頁:html,css - iPhone上單頁網站的100%div高度

​​

和下面的代碼:

body, html { 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 

 
.section { 
 
    height: 100%; 
 
    position: relative; 
 
} 
 

 
.one, .three { 
 
    background-color: #666; 
 
} 
 

 
.two { 
 
    background-color: #222; 
 
} 
 

 
.bottom { 
 
    position: absolute; 
 
    bottom: 20px; 
 
    right: 0px; 
 
    left: 0px; 
 
} 
 

 
p { 
 
    color: #fff; 
 
    text-align: center; 
 
} 
 

 
.nav { 
 
    position: fixed; 
 
    top: 0px; 
 
    height: 50px; 
 
    width: 100%; 
 
    background-color: #fff; 
 
    z-index: 1; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="UTF-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
 
    <title>Document</title> 
 
    <link rel="stylesheet" href="reset.css"> 
 
    <link rel="stylesheet" href="main.css"> 
 
</head> 
 
<body> 
 

 
<!--nav--> 
 
<div class="nav"></div> 
 

 
<!--Section1--> 
 
<div class="section one"> 
 
<div class ="bottom"><p>By Juan Portillo</p></div> 
 
</div> 
 

 
<!--Section2--> 
 
<div class="section two"> 
 

 
</div> 
 

 
<!--Section3--> 
 
<div class="section three"> 
 

 
</div> 
 

 
</body> 
 
</html>

它在我的桌面上的偉大工程。但我在我的iPhone上嘗試過,第一部分佔據了網頁的整個高度,而不僅僅是瀏覽器的高度,所以它最終「隱藏」了其他部分。

我在堆棧溢出以及其他一些網站上做了幾次搜索,但我找不到修復程序。任何幫助將不勝感激。

回答

0
height: 100vh 

應該做的伎倆

vh = viewport height