Absolute positioning a bootstrap navbar interferes with alignment of items

629 views Asked by At

I am trying to create a navbar overtop a carousel. The navbar should have two sets of links;

1: Links aligned to the left

2: Social media links aligned to the right

I have have done this successfully with the code below;

HTML

<nav class="navbar navbar-expand-lg navbar-light bg-light" id = "navigation">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">GALLERIES <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">ABOUT</a>
      </li>
    </ul>

    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="navbar-brand" href="#">
          <img src="images/icons/shopping-cart.png" class = "nav_icon" alt = "">
        </a>
      </li>
      <li class="nav-item">
        <a class="navbar-brand" href="#">
          <img src="images/icons/twitter.png" class = "nav_icon" alt = "">
        </a>
      </li>
    </ul>

  </div>
</nav>

CSS

#navigation{
  z-index: 999;
  background:0 !important;
  font-size: 1.5vw;
  color: #fff !important;
  /*position: absolute;*/
}

.nav_icon{
  width: 2vw;
  height: 2vw;
}

This yields the following result;

sample

However, I want the navbar to be overtop my carousel (code for the carousel not included). Adding 'position: absolute' interferes with my alignment like so;

sample2

Why is this happening? How can I get the same results without messing up the alignment of the links?

0

There are 0 answers