Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the brand logo in Bootstrap 4 navbar to the left edge?

I have a logo as shown below.

<nav class="navbar navbar-fixed-top navbar-light bg-primary">
  <div class="container-fluid">
    <img class="navbar-brand" src="logo.png" alt="logo">
    <ul class="nav navbar-nav">
      <li class="nav-item"><a href="#" class="nav-link">START</a></li>
      ...
    </ul>
  </div>
</nav>

Bootstrap adds a piece of padding on the left resulting in the following offset from the edge.

enter image description here

Since our logo is a cut off circle, we want it to be placed precisely at the edge to create illusion of a real circle but sticking outside of the browser. I've tried to set a negative margin on the left side but it only moved the image, still retaining the weird edge as shown below.

<img class="navbar-brand" src="logo.png" alt="logo" style="margin-left: 0px;">

enter image description here

What can I do about it?

like image 650
Konrad Viltersten Avatar asked Dec 23 '16 22:12

Konrad Viltersten


People also ask

How do I align navbar brand to right?

Move the brand above the navbar-header and give it the class navbar-right. This puts your brand on right when in desktop views, and it goes left in mobile views, properly keeping the menu button as the rightmost element.

How do I center my logo in Bootstrap 4?

For aligning at the center, we need to use . mx-auto and . d-block classes of bootstrap.


1 Answers

You can use row instead of container-fluid. these two have opposite margins.

https://jsfiddle.net/gsb3ohd2/

<nav class="navbar navbar-fixed-top navbar-light bg-primary">
  <div class="row">
    <img class="navbar-brand" src="logo.png" alt="logo">
    <ul class="nav navbar-nav">
      <li class="nav-item"><a href="#" class="nav-link">START</a></li>
      ...
    </ul>
  </div>
</nav>
like image 158
Banzay Avatar answered Oct 02 '22 23:10

Banzay