边距未设置为零

时间:2014-06-03 17:16:35

标签: html css css3

我将文章标记和标题标记之间的边距设置为0,但我仍然看到它们之间有一个空格,显示我的身体为黄色。我试图将标题和文章之间的空间最小化为0而不将正文中的所有元素设置为马林:0

这是我的CSS。

body 
{
background-color: yellow;
margin: 0;
}

header > * {
margin: 0;
float: left;
}

header
{
background-color: white ;
width: 100%;
height: 40px;

}

article > * {
margin: 0;
}

article
{
background-color: red;
}

#search {
background-color: #a6dbed;
height: 500px;
}

#mostdesired 
{
background-color: #c7d1d6;
height: 200px;
}

这是html

<body>
    <header>
        <h1>Welcome</h1>
        <input type="text"/>
        <input type="submit" value="Search"/>
    </header>
    <article>
        <section id="search"><h2>this is the search</h2>@RenderBody()</section>
        <section id="mostdesired" ><h2>This is the most section</h2></section>
    </article>
</body>

1 个答案:

答案 0 :(得分:5)

您需要从<h2>元素中删除默认边距:

section h2 {
    margin:0;
}

<强> jsFiddle example