<header>和<main>之间无法解释的差距

时间:2015-05-29 18:38:59

标签: html css html5 css3

我似乎无法摆脱我的标题和主要内容之间存在的空间。您将在背景图像上方和导航下方看到黑色背景。任何帮助都会很棒。

<!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);
}

2 个答案:

答案 0 :(得分:1)

这是由位于<h1>的{​​{1}}的上边距引起的。这很容易在下面的代码片段中重现。

<div id="top-section-content">
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;
}

您可以通过使用顶部填充替换顶部边距来解决此问题,或者您可以向其容器添加1个像素的顶部填充。

答案 1 :(得分:0)

(叹气)再次折磨利润率。 h1的边距由其所在的section共享,导致该部分在屏幕上开始低于预期。

解决方案:从h1删除边距。

h1 {margin:0}

请参阅fiddle

相关问题