2015-05-29 39 views
1

我似乎無法擺脫我的標題和主要內容之間存在的這個空間。您會在背景圖像上方和導航下方看到黑色背景。任何幫助都會很棒。不明原因的差距<header>和<main>

<!doctype html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Awesome Landing Page</title> 
    <link rel="stylesheet" type="text/css" href="CSS/style.css"> 
    </head> 
<body> 
    <header> 
     <div id="header-container"> 
      <div class="col-3"> 
       <img class="logo" src="Images/logo-dark.png" height="18" width="143"> 
      </div> 
      <div class="col-3"> 
      <nav> 
       <ul class="menu"> 
        <li>Home</li> 
        <li>Features</li> 
        <li>About</li> 
        <li>Signup</li> 
       </ul>  
      </nav> 
      </div> 
      <div class="col-3"> 
       <a href="#" class="getStartedBTN">Get Started</a> 
      </div> 
     </div><!-- Header-Container Ends Here --> 
    </header> 
    <main> 
    <section> 
     <div id="top-section-main"> 
      <div id="top-section-content"> 
       <h1>Awesome looks so good</h1> 
       <p>Awesome is the landing page you wish you had when you started.</p> 
      </div> 
     </div>  
    </section> 
    <section></section> 
    <section></section> 
    <section></section> 
    <section></section> 
    <section></section> 
    </main> 
    <footer></footer> 
</body> 
</html> 

CSS

html { 
    font-family: "Lato", "Helvetica Neue", "Helvetica", "Arial", sans-serif; 
} 
body { 
    background-color: black; 
    margin: 0; 
} 
header { 
    height: 80px; 
    background-color: #ffffff; 
} 
#header-container { 
    width: 75%; 
    margin: auto; 
} 
.col-3 { 
    width: 33%; 
    float: left; 
} 
.logo { 
    padding-top: 30px; 
} 
.menu { 
    margin-top: 32px; 
} 
.menu li { 
    list-style-type: none; 
    display: inline; 
    font-size: .85em; 
    color: #8e8e8e; 
    padding-right: 30px; 
} 
.getStartedBTN { 
    background-color: #6dc77a; 
    border-radius: 28px; 
    -moz-border-radius:28px; 
    -webkit-border-radius:28px; 
    text-decoration: none; 
    color: #ffffff; 
    padding: 10px 26px; 
    margin-top: 20px; 
    display: inline-block; 
    font-size: 17px; 
    float: right; 
} 
#top-section-main { 
    height: 740px; 
    background-image: url(../Images/friends.jpg); 
} 
+0

你需要證明你的標記,如果你確實需要幫助。 – oobivat

+0

代碼或圖像在哪裏供我們看? – MTahir

+0

嘿不小心刪了。剛剛編輯 –

回答

1

這是由位於<div id="top-section-content"><h1>的上邊距引起的。這很容易在下面的代碼片段中複製。

body { 
 
    background:gray; 
 
} 
 

 
header { 
 
    height:50px; 
 
    background:orange; 
 
} 
 

 
section { 
 
    background:red; 
 
} 
 

 
#fixed-1 section { 
 
    padding-top:1px; 
 
} 
 

 
#fixed-2 h1 { 
 
    margin-top:0; 
 
    padding-top:16px; 
 
}
<div> 
 
    <header></header> 
 
    
 
    <section> 
 
     <h1>hello i'm broken</h1> 
 
    </section> 
 
</div> 
 

 
<div id = "fixed-1"> 
 
    <header></header> 
 
    
 
    <section> 
 
     <h1>hello i'm fixed by a padding on the container!</h1> 
 
    </section> 
 
</div> 
 

 
<div id = "fixed-2"> 
 
    <header></header> 
 
    
 
    <section> 
 
     <h1>hello i'm fixed by replacing the margin with a padding!</h1> 
 
    </section> 
 
</div>

您可以通過頂部的填充替換上邊距,而不是解決這個問題,或者你可以添加1個像素的頂部填充到其容器。

0

(嘆氣)再次崩潰的利潤率。 h1的邊距由section共享,導致屏幕在屏幕上低於預期。

解決方法:從h1中刪除餘量。

h1 {margin:0} 

fiddle