I'm working in a responsive web page and now I'm making one of its media queries. I need to get my header and the first section of my main together, but I'm having trouble with it. I already tried to remove the margin of my header, of my main and the first section of my main, but even so there's a space between the header and the section. Why is it happening? Some excerpts of my code are below:
Obs: please note that I tried to eliminate some margins but the problem is not solved.
@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>
To remove the vertical gap completely, add the following rules:
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>