0

I'm working on my website navigation on mobile view, a pure css hamburger menu, my problem is there is a gap between the header(which includes the logo and hamburger menu) and the dropped down list of my navigation.

/*
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

body {
    line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section {
    display:block;
}

nav ul {
    list-style:none;
}

blockquote, q {
    quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content:'';
    content:none;
}

a {
    margin:0;
    padding:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

/* change colours to suit your needs */
ins {
    background-color:#ff9;
    color:#000;
    text-decoration:none;
}

/* change colours to suit your needs */
mark {
    background-color:#ff9;
    color:#000;
    font-style:italic;
    font-weight:bold;
}

del {
    text-decoration: line-through;
}

abbr[title], dfn[title] {
    border-bottom:1px dotted;
    cursor:help;
}

table {
    border-collapse:collapse;
    border-spacing:0;
}

/* change border colour to suit your needs */
hr {
    display:block;
    height:1px;
    border:0;  
    border-top:1px solid #cccccc;
    margin:1em 0;
    padding:0;
}

input, select {
    vertical-align:middle;
}

/*--------------MY CODE----------*/

/*--------------MY CODE----------*/

/*MOBILE VIEW*/
* {
    text-decoration: none;
    font-family: Catamaran, sans-serif;
}

header {
    background-color: #dbd3d34b;
    height: 100px;
    box-shadow: 1px 1px rgb(177, 175, 175);
    z-index: 1;
}

.logo {
    display: block;
    float: left;
    margin: 27px 0;
}

.logo img{
    width: 200px;
    height: 50px;
}

nav ul {
    overflow: hidden;
}
nav ul li a {
    display: block;
    background-color: #f2f2f2;
    font-family: Roboto, sans-serif;
    font-size: 16px;
    padding: 20px;
    font-weight: 400;
    color: #111;
    border-bottom: 1px solid rgb(8, 189, 53);
    position: relative;
    z-index: 1;
}
nav ul li a:hover {
    color: rgb(8, 189, 53);
}

/*-------HAMBURGER MENU-------------*/
nav ul {
   border: 1px solid red;
}
nav .menu {
    clear: both;
    max-height: 0;
    transition: max-height .2s ease-out;
}
nav .menu-icon {
    margin: 30px 0;
    padding: 20px 15px;
    position: relative;
    float: right;
}
nav .menu-icon .nav-icon {
    background-color: #111;
    display: block;
    height: 3px;
    width: 25px;
    position: relative;
    transition: background .2s ease-out;
}
nav .menu-icon .nav-icon:before {
    background-color: #111;
    content:"";
    height: 100%;
    width: 100%;
    position: absolute;
    transition: all .2s ease-out;
    top: 7px;
}
nav .menu-icon .nav-icon:after {
    background-color: #111;
    content:"";
    height: 100%;
    width: 100%;
    position: absolute;
    transition: all .2s ease-out;
    bottom: 7px;
}
.menu-btn {
    display: none;
}

nav .menu-btn:checked ~ .menu {
    max-height: 260px;  
}

nav .menu-btn:checked ~ .menu-icon .nav-icon {
  background-color:transparent;
}
nav .menu-btn:checked ~ .menu-icon .nav-icon:before {
  transform: rotate(-45deg);
  top:0;
}
nav .menu-btn:checked ~ .menu-icon .nav-icon:after {
    transform: rotate(45deg);
    top:0;
}
/*----END OF HAMBERGER MENU*/

/*---------DESKTOP DISPLAY*/
@media only screen and (min-width: 1000px) {
.menu-btn {
    display: none;
}
nav .menu {
    clear: none;
    max-height: none;
}
nav .menu-icon {
    display: none
}
.logo {
    display: block;
    float: left;
    margin: 4px 0;
}

.logo img{
    width: 380px;
    height: 86px;
}

nav {  
    float : right;
    width: 600px;
    height: 100px;
    margin-right: 80px;
}
nav ul {
    height: inherit;
    display: flex;
    flex-flow: row;
    justify-content: space-between;
    align-items: center; 
}

nav ul li a {
    font-size: 24px;
    font-weight: 600;
    color: #111;
    border-bottom: none;
}


.main {
    background-image: url("img/header.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    width: 100%;
    height: 400px;
    margin-top: 1px;

    display: flex;
    justify-content: center;
    align-items: center;
}

.main .header-text{
    width: 600px;
    text-align: center;
}

.main .header-text h1{
    font-size: 68px;
    color: #f2f2f2;
    text-shadow: 1px 1px #111, -0.5px -0.5px #111;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type ="text/css" href="main-page.css">
    <title>Portfolio Michael</title>
</head>
<body>
    <header class="header">
        <div class="logo">
            <img src="img/logo.png" alt="Web Page Logo">
        </div>
        <nav>
            
        <input class="menu-btn" type="checkbox" id="menu-btn">
        <label class="menu-icon" for="menu-btn"><span class="nav-icon"></span></label> 
        
        <ul class="menu">
            <li><a href="#">Excercises</a></li>
            <li><a href="#">Projects</a></li>
            <li><a href="#">About</a></li>
        </ul>
        
        </nav>
    </header>

    <main>
        <section class="main">
            <div class="header-text">
                <h1>Hi! I'm Michael! And this is my Website</h1>
            </div>    
        </section>
    </main>
    
</body>
</html>
If youll run this code you can see in mobile view that there is a small gap between header and my main page, i made a red border to highlight the gap.

I tried to add a negative margin top and margin 0 in my "nav . menu" but nothing happened.

  • Is this your complete code, it looks like you have not included a reset.css or normalise.css ? some more info here https://stackoverflow.com/questions/6887336/what-is-the-difference-between-normalize-css-and-reset-css Also you'll get better help if you setup a jsbin or codepen with an example for people to look at. https://stackoverflow.com/help/minimal-reproducible-example – NeilWkz Oct 10 '19 at 15:11
  • Thank you for this, i added a snippet, Hope you can find my mistake here – Nami_Raven Oct 11 '19 at 11:24

2 Answers2

1

The problem lies with the nav .menu

You can fix this by simply specifying a margin of 0 in your CSS.

nav .menu {
  clear: both;
  max-height: 0;
  transition: max-height 0.2s ease-out;
  margin: 0;
}

enter image description here

bananabrann
  • 556
  • 7
  • 26
-1

I can't believe i solved my own problem, i just wanted to share, by looking at Inspect element, my label which has a class of menu-icon my margin overlaps within the header area causing extra space.