Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove left padding from Bootstrap navbar and maintain correct responsive behaviour

I would like to remove the left padding from the navbar below:

enter image description here

and top padding in a narrow viewport:

enter image description here

Navbar code & JSFiddle:

<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">About</a></li>
      <li><a href="#">Events</a></li>
      <li><a href="#">News</a></li>
      <li><a href="#">Discuss</a></li>
    </ul>
  </div>
</nav>

https://jsfiddle.net/wx6bx3pr/

Already attempted solution - setting the padding of .container-fluid to zero gets the desired outcome in the wide viewport:

enter image description here

.container-fluid
{
  padding: 0;
}

Except completely breaks it in a narrow viewport, with the active menu item protruding beyond the navbar, and no spacing between the container and the text of menu items:

enter image description here

How do I get the desired solution without breaking the narrow viewport?

Many thanks.

like image 252
Jonny Rylands Avatar asked Jan 05 '23 19:01

Jonny Rylands


1 Answers

Try a negative margin on the navbar like this..

@media (min-width: 768px) {
  .navbar-nav {
    float: left;
    margin: 0;
    margin-left: -15px;
  }
}

.navbar-nav {
    margin: 0 -15px;
}

http://codeply.com/go/leAaYlOaYd

like image 147
Zim Avatar answered Jan 22 '23 15:01

Zim