2016-05-29 41 views
0

我有一個導航欄和主頁的簡單頁面。導航欄是固定的,主頁佔據屏幕的100%。觀看者然後從主頁滾動查看剩餘的網頁內容。問題縮放字體到屏幕尺寸

我在移動設備或屏幕尺寸較小的設備上查看時遇到字體無法縮放的問題。我相信這是由於我改變了導航欄佔據100%的寬度,而主頁佔據了100%的高度。第1部分下的文本正確縮放(當屏幕較小時字體變大)。

如何讓主頁和導航欄增加字體?

h1{ 
 
    text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 
 
      0px 8px 13px rgba(0,0,0,0.1), 
 
      0px 18px 23px rgba(0,0,0,0.1); 
 
} 
 
html { 
 
    height: 100%; 
 
    min-height: 100%; 
 
} 
 
body { 
 

 
    background: #1A3742; 
 
    font-family: 'Source Sans Pro', sans-serif; 
 
    color: white; 
 
    margin: auto 100px; 
 
    height: 100%; 
 
} 
 
#header { 
 
    background: gray; 
 
    padding: 28px 0 26px; 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: 1000; 
 
    width: 100%; 
 

 
} 
 

 
#top{ 
 
    text-align: center; 
 
    height: 100%; 
 

 
} 
 
#home-content{ 
 
    position: relative; 
 
    top: 50%; 
 
    transform: translateY(-50%); 
 
} 
 
a[href="#top"] { 
 
    margin-left:100px; 
 
    margin-right:50px; 
 
    vertical-align: middle; 
 
    text-decoration: none; 
 
    font-weight: bold; 
 
} 
 
a img{ 
 
    vertical-align:middle; 
 
} 
 
.content { 
 
    margin-left:75px; 
 
    margin-top:25px; 
 
    overflow: hidden; 
 
} 
 
.content p{ 
 
    margin-top: 0px; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title></title> 
 
    <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700' rel='stylesheet' type='text/css'> 
 
\t <link rel="stylesheet" type="text/css" href="style.css"> 
 
</head> 
 
<body> 
 
    <header id="header"> 
 
     <a href="#top">Name</a> 
 
     <a href=""> 
 
      <img src="" alt="img" height="24" width="24"> 
 
     </a> 
 
    </header> 
 

 
    <div id="top"> 
 
     <div id = "home-content"> 
 
      
 
      <h1>Top</h1> 
 
      <h2>Sub title</h2> 
 
      <p> 
 
      This text does not scale at all. 
 
      </p> 
 
     </div> 
 
    </div> 
 
    <div id="section1"> 
 
     <h1>Section 1</h1> 
 
     <div class = "content"> 
 

 
     <p> 
 
     This scales with the screen. 
 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
 
     tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
 
     quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
 
     consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
 
     cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
 
     proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
 

 
     </p> 
 

 
     </div> 
 
    </div> 
 
</body> 
 
</html>

這裏是移動的例子,顯示了頂部的文本不結垢,但SECTION1縮放正確。 enter image description here

這是谷歌瀏覽器中的Galaxy S5。主頁/頂部和導航欄中的文本應該按照section1文本的方式進行縮放。 我該如何解決它,所以一切都縮放到屏幕上?

回答

0

首先,它們都不是縮放。它是應用瀏覽器默認值,因爲你沒有在提供的CSS中設置任何字體大小。您可以在網頁檢查器中測試它(請記住在激活它之後重新加載頁面)。

您可以使用vh(視圖高度)或vw(視圖寬度)作爲字體的百分比調整。

+0

據我所知,它使用默認值,但爲什麼第1部分的字體大小會增加,但導航欄和頂部不會增加字體大小?我希望他們都有相同的字體大小。 – eric

+0

激活網絡檢查器移動模式後更新您的瀏覽器,我看到相同的,然後記得更新。 – LordNeo

+0

我刷新了,但沒有修復它。 #top的高度爲100%,這改變了文本的大小。我試圖找出如何讓它不這樣做,類似於從未改變的底部部分。不知道如何以簡單的方式做到這一點。如果我在#top中刪除高度:100%,則一切正常。但是,我需要保持高度:100% – eric