为什么我的 'header' 和我的 'main' (HTML) 之间有一个 margin/space?
Why there is a margin/space between my 'header' an my 'main' (HTML)?
我正在处理一个响应式网页,现在我正在处理其中一个媒体查询。我需要将我的 header 和我的主要部分的第一部分放在一起,但我遇到了麻烦。我已经尝试删除我的 header、我的主要内容和我的主要内容的第一部分的边距,但即使如此,header 和该部分之间仍有一个 space。为什么会这样?我的代码的一些摘录如下:
Obs:请注意,我尝试消除了一些边距,但问题并未解决。
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Oxygen');
body {
font-family: Arial, Helvetica, sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6,
#firstsection p {
font-family: 'Oxygen', sans-serif;
}
a {
text-decoration: none;
}
header {
margin-bottom: 50px;
}
header img,
main img {
display: block;
margin-right: auto;
margin-left: auto;
}
nav ul {
list-style: none;
text-align: center;
background-color: rgb(90, 32, 102);
line-height: 3.125em;
padding: 1em 0;
width: 105.7%;
}
header a {
color: white;
}
nav ul li:hover {
background-color: rgb(98, 46, 109);
}
main {
width: 105.75%;
}
#firstsection {
text-align: center;
margin-bottom: 45px;
}
#firstsection h2 {
color: rgb(85, 26, 119);
font-size: 1.35em;
margin-bottom: 1.38888889em;
letter-spacing: 0.04629629629em;
}
#firstsection p {
font-weight: bold;
color: rgb(167, 120, 199);
margin: 1.03025em;
line-height: 1.5em;
}
/* END OF FIRST LAYOUT */
/* START OF FIRST MEDIA QUERIE */
@media screen and (min-width: 48.75em) and (max-width: 74em) {
header {
margin-bottom: 0;
}
header img {
margin-left: 10px;
}
main {
margin-top: 0;
}
#firstsection {
background-color: rgb(85, 26, 119);
margin-top: 0;
}
#firstsection h2 {
color: white;
}
}
<header>
<img src="images/logo_mob.svg" alt="Logo Range Hotels">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="firstsection">
<h2>An exciting new venture over the<br>range</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipisicing elit.</p>
<a href="#">Get Started</a>
</section>
要完全删除垂直间隙,请添加以下规则:
header,
nav ul {
margin-bottom: 0;
}
#firstsection > h2 {
margin-top: 0;
}
演示
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Oxygen');
body {
font-family: Arial, Helvetica, sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6,
#firstsection p {
font-family: 'Oxygen', sans-serif;
}
a {
text-decoration: none;
}
header {
margin-bottom: 50px;
}
header img,
main img {
display: block;
margin-right: auto;
margin-left: auto;
}
nav ul {
list-style: none;
text-align: center;
background-color: rgb(90, 32, 102);
line-height: 3.125em;
padding: 1em 0;
width: 105.7%;
}
header a {
color: white;
}
nav ul li:hover {
background-color: rgb(98, 46, 109);
}
main {
width: 105.75%;
}
#firstsection {
text-align: center;
margin-bottom: 45px;
}
#firstsection h2 {
color: rgb(85, 26, 119);
font-size: 1.35em;
margin-bottom: 1.38888889em;
letter-spacing: 0.04629629629em;
}
#firstsection p {
font-weight: bold;
color: rgb(167, 120, 199);
margin: 1.03025em;
line-height: 1.5em;
}
/* END OF FIRST LAYOUT */
/* START OF FIRST MEDIA QUERIE */
@media screen and (min-width: 48.75em) and (max-width: 74em) {
header {
margin-bottom: 0;
}
header img {
margin-left: 10px;
}
main {
margin-top: 0;
}
#firstsection {
background-color: rgb(85, 26, 119);
margin-top: 0;
}
#firstsection h2 {
color: white;
}
}
header,
nav ul {
margin-bottom: 0;
}
#firstsection > h2 {
margin-top: 0;
}
<header>
<img src="images/logo_mob.svg" alt="Logo Range Hotels">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="firstsection">
<h2>An exciting new venture over the<br>range</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipisicing elit.</p>
<a href="#">Get Started</a>
</section>
</main>
我正在处理一个响应式网页,现在我正在处理其中一个媒体查询。我需要将我的 header 和我的主要部分的第一部分放在一起,但我遇到了麻烦。我已经尝试删除我的 header、我的主要内容和我的主要内容的第一部分的边距,但即使如此,header 和该部分之间仍有一个 space。为什么会这样?我的代码的一些摘录如下:
Obs:请注意,我尝试消除了一些边距,但问题并未解决。
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Oxygen');
body {
font-family: Arial, Helvetica, sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6,
#firstsection p {
font-family: 'Oxygen', sans-serif;
}
a {
text-decoration: none;
}
header {
margin-bottom: 50px;
}
header img,
main img {
display: block;
margin-right: auto;
margin-left: auto;
}
nav ul {
list-style: none;
text-align: center;
background-color: rgb(90, 32, 102);
line-height: 3.125em;
padding: 1em 0;
width: 105.7%;
}
header a {
color: white;
}
nav ul li:hover {
background-color: rgb(98, 46, 109);
}
main {
width: 105.75%;
}
#firstsection {
text-align: center;
margin-bottom: 45px;
}
#firstsection h2 {
color: rgb(85, 26, 119);
font-size: 1.35em;
margin-bottom: 1.38888889em;
letter-spacing: 0.04629629629em;
}
#firstsection p {
font-weight: bold;
color: rgb(167, 120, 199);
margin: 1.03025em;
line-height: 1.5em;
}
/* END OF FIRST LAYOUT */
/* START OF FIRST MEDIA QUERIE */
@media screen and (min-width: 48.75em) and (max-width: 74em) {
header {
margin-bottom: 0;
}
header img {
margin-left: 10px;
}
main {
margin-top: 0;
}
#firstsection {
background-color: rgb(85, 26, 119);
margin-top: 0;
}
#firstsection h2 {
color: white;
}
}
<header>
<img src="images/logo_mob.svg" alt="Logo Range Hotels">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="firstsection">
<h2>An exciting new venture over the<br>range</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipisicing elit.</p>
<a href="#">Get Started</a>
</section>
要完全删除垂直间隙,请添加以下规则:
header,
nav ul {
margin-bottom: 0;
}
#firstsection > h2 {
margin-top: 0;
}
演示
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Oxygen');
body {
font-family: Arial, Helvetica, sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6,
#firstsection p {
font-family: 'Oxygen', sans-serif;
}
a {
text-decoration: none;
}
header {
margin-bottom: 50px;
}
header img,
main img {
display: block;
margin-right: auto;
margin-left: auto;
}
nav ul {
list-style: none;
text-align: center;
background-color: rgb(90, 32, 102);
line-height: 3.125em;
padding: 1em 0;
width: 105.7%;
}
header a {
color: white;
}
nav ul li:hover {
background-color: rgb(98, 46, 109);
}
main {
width: 105.75%;
}
#firstsection {
text-align: center;
margin-bottom: 45px;
}
#firstsection h2 {
color: rgb(85, 26, 119);
font-size: 1.35em;
margin-bottom: 1.38888889em;
letter-spacing: 0.04629629629em;
}
#firstsection p {
font-weight: bold;
color: rgb(167, 120, 199);
margin: 1.03025em;
line-height: 1.5em;
}
/* END OF FIRST LAYOUT */
/* START OF FIRST MEDIA QUERIE */
@media screen and (min-width: 48.75em) and (max-width: 74em) {
header {
margin-bottom: 0;
}
header img {
margin-left: 10px;
}
main {
margin-top: 0;
}
#firstsection {
background-color: rgb(85, 26, 119);
margin-top: 0;
}
#firstsection h2 {
color: white;
}
}
header,
nav ul {
margin-bottom: 0;
}
#firstsection > h2 {
margin-top: 0;
}
<header>
<img src="images/logo_mob.svg" alt="Logo Range Hotels">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="firstsection">
<h2>An exciting new venture over the<br>range</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipisicing elit.</p>
<a href="#">Get Started</a>
</section>
</main>