1

So I've created a navbar and I've got it working with horizontal navigation. However I've got these "gaps" between the navbar as they show in the picture below, however I can still click between these gaps.

pic1

Here is the JSFiddle (SCSS wouldnt work so I used the compiled CSS):

http://codepen.io/anon/pen/JRRowb

Here is the nav code I'm using, variables are just colors that I'm using:

HTML:

<nav id="nav">
    <span class="brand">Brand Name</span>
    <ul>
        <li><a href="about.html">About <i class="fa fa-angle-down"></i></a></li>
        <li><a href="portfolio.html">Portfolio</a></li>
        <li><a href="contact.html">Contact Us</a></li>
    </ul>
    <a class="nav-bars"><i class="fa fa-bars"></i></a>
</nav>

SCSS (Sass):

/*----------------
    Navbar Styles
  ----------------*/
.nav_fixed {
    position: fixed;
    top: -($info_bar_height / 4);
    z-index: 100;
}
nav {
    height: $navbar_height;
    width: 100%;
    margin: 0;

    color: $navbar_color;
    background: $navbar_background_color;
    font-weight: bold;
    letter-spacing: 0.025em;
    line-height: $navbar_height;
    text-transform: uppercase;

    -webkit-box-shadow: 0 8px 6px -6px $navbar_shadow_color;
    -moz-box-shadow: 0 8px 6px -6px $navbar_shadow_color;
    box-shadow: 0 8px 6px -6px $navbar_shadow_color;

    .brand {
        float: left;
        margin-left: $navbar_padding;
        font-size: 20px;
    }

    ul {
        margin: 0;
        padding: 0;
        display: flex;
        float: right;
        margin-right: $navbar_padding - 20px;

        li {
            display: inline-block;
            list-style: none;
            cursor: pointer;

            a {
                color: $navbar_color;
                text-decoration: none;
                padding: ($navbar_height / 4) 20px;
                margin: 10px 0;

                @include transition(all .175s ease-in-out);
            }
            a.nav-bars {
                display: none;
            }
        }
        li:hover {
            a {
                color: $link_hover_color;
            }
        }
    }

    a.nav-bars {
        display: none;
    }
}

/*--------------------
    Responsive Styles
  --------------------*/

@media only screen and (min-width: 320px) and (max-width: 768px) {
    .info_bar {
        display: none;
    }

    nav {
        position: fixed;
        z-index: 100;

        -webkit-box-shadow: none;
        -moz-box-shadow: none;
        box-shadow: none;

        ul {
            position: absolute;
            top: $navbar_height + ($navbar_padding / 4) - 10px;
            display: none;
            height: 100%;
            width: 100%;
            z-index: 90;
        }
        a.nav-bars {
            margin: 0;
            padding: 0;
            display: inline-block;
            text-decoration: none;
            float: right;
            margin-right: $navbar_padding;
            font-size: 24px;
            cursor: pointer;

            @include transition(all .375s ease-in-out);
        }

        li {
            display: block;
            width: 100%;
            padding: 0;
            margin: 0;

            a {
                position: relative;
                display: block;
                margin: 0;
                padding: 0;

                color: $navbar_color;
                background: $navbar_background_color;
                font-weight: bold;
                letter-spacing: 0.025em;
                line-height: 40px;
                border-bottom: 1px solid darken($navbar_background_color, 5);
                border-top: 1px solid darken($navbar_background_color, 5);
            }
        }
    }
}

.rotate {
    @include transform(rotate(90deg));
}

JS:

$(function() {
    var nav = $('nav');
    var info_bar_height = $('#info_bar').height();

    $(window).scroll(function() {
        if($(this).scrollTop() > info_bar_height) {
            nav.addClass('nav_fixed');
        } else {
            nav.removeClass('nav_fixed');
        }
    });

    var bars = $('.nav-bars');
    var menu = $('nav ul');
    var menuHeight = menu.height();

    $(bars).on('click', function(e) {
        e.preventDefault();
        bars.toggleClass('rotate');
        menu.slideToggle(375, "linear");
    });
});
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38

2 Answers2

1

This should do the trick, where you change the CSS like below

Updated codepen: http://codepen.io/anon/pen/QKKbyZ

nav ul li {
  /* display: inline-block;       remove, not needed as you use flex on its parent  */
  list-style: none;
  cursor: pointer; }
  nav ul li a {
    color: #444;
    text-decoration: none;
    padding: 22.5px 20px;
    /* margin: 10px 0;             remove, creates additional gaps    */
Asons
  • 84,923
  • 12
  • 110
  • 165
  • Thanks! By the way, is there any way to make the slide down smoother? – madcrazydrumma Sep 18 '16 at 17:54
  • 1
    @madcrazydrumma You are welcome. Regarding the transition, post a new question and I'm sure some one have a fix for that too, as I have limited time right now to look into that :) – Asons Sep 18 '16 at 18:02
  • 2
    Its not smooth cos you've set a height of `100%` on your absolute positioned `nav ul`. And when you slideToggle to reveal it, its height is only as tall as its ancestor `nav`. You should probably remove that. – AA2992 Sep 18 '16 at 18:08
  • @AnkithAmtange fixed! Cheers laddies! – madcrazydrumma Sep 18 '16 at 18:20
-1

remove the margin from 'nav ul li' and remove display:inline-block from 'a.nav-bars'

sean
  • 1,220
  • 9
  • 8