Center the logo within the NavBar

I'm having trouble centering the logo in my navbar and getting elements to spread out from the logo on both sides. I also want to position the buttons at the end of the navigation bar.

Here's the desired layout In my code, I attempted to create two columns inside the navbar where one column occupies 80% width for storing 5 elements, and the other takes up 20% width for the buttons at the end. I'm unsure about the best approach to achieve this.

<nav class="navbar navbar-expand-md navbar-dark bg-dark py-3">
    <ul class=" col-sm-10 navbar-nav justify-content-center">
        <li class="nav-item"><a href="#" class="nav-link">Products</a></li>
        <li class="nav-item"><a href="#" class="nav-link">My Products</a></li>

        <li><img src="../../assets/KLion.jpg" alt="logo" style="width:70px; height:50px;"></li>
        <li class="nav-item"><a href="#" class="nav-link">About KLion</a></li>
        <li class="nav-item"><a href="#" class="nav-link">News & Updates</a></li>

    </ul>
    <ul class=" col-sm-1 navbar-nav justify-content-between py-3 ">

        <button type="button" class="btn">
            <img src="../../assets/Group 1.png" alt="logo" style="width:80px; height:20px;">
        </button>
        <button type="button" class="btn">
            <img src="../../assets/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98ebf0f7e8e8f1f6ffb5fbf9eaecd8aae0b6e8f6ff">[email protected]</a>" alt="logo" style="width:20px; height:20px;">
        </button>
    </ul>

</nav>
.navbar-nav > li{
  margin-left: 130px;
}

Answer №1

Hopefully this solution proves useful to you

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<nav class="navbar navbar-default" role="navigation">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>    
  </div>
  <div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li class="navbar-left"><a href="#">Left 1</a></li>
      <li class="navbar-left"><a href="#">Left 2</a></li>
      <li class="active"><a href="#" class="nav-link">Products</a></li>
      <li class=""><a href="#" class="nav-link">My Products</a></li>
      <li><img src="your_img_path" alt="logo" style="width:70px; height:50px;"></li>
      <li class=""><a href="#" class="nav-link">About KLion</a></li>
        <li class=""><a href="#" class="nav-link">News & Updates</a></li>

      <li class="navbar-right"><button type="button" class="btn">
            <img src="../../assets/Group 1.png" alt="logo" style="width:80px; height:20px; ">
        </button></li>
      <li class="navbar-right"  style="margin-right: 20px;"><button type="button" class="btn">
            <img src="../../assets/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="77041f1807071e19105a1416050337450f59071910">[email protected]</a>" alt="logo" style="width:20px; height:20px;">
        </button></li>
    </ul>
  </div>
</nav>

@media (min-width: 768px) {
  .navbar-nav {
    width: 100%;
    text-align: center;
  }
  .navbar-nav > li {
    float: none;
    display: inline-block;
  }
  .navbar-nav > li.navbar-right {
    float: right !important;
  }
}

Appreciate your time and consideration

Answer №2

.main-nav{
  display:flex;
  flex-direction:row;
  justify-content:space-evenly;
  width:100%;
}
.main-nav ul:first-child{
  margin-left:20%;
  display:flex;
  flex-direction:row;
  justify-content:space-between;
  width:60%;
}
.main-nav ul:last-child{
  width:20%;
  display:flex;
  flex-direction:row;
  justify-content:space-evenly;
}

Check out the code on CodePen here!

Answer №3

If you're looking for a similar effect and want to position it within a specific tag in the style block, you can try this approach by adjusting margins and padding for button size.

<html>
    <head></head>
<style>
    .navbar-nav > a{
        margin-left: 50px;
    }
    img{
        margin-left: 50px;
    }
</style>
    <body>
        <nav class="navbar navbar-expand-md navbar-dark bg-dark py-3">
            <div class=" col-sm-10 navbar-nav justify-content-center">
                <a href="#" class="nav-link">Products</a></li>
                <a href="#" class="nav-link">My Products</a></li>
                <img src="../../assets/KLion.jpg" alt="logo" style="width:70px; height:50px;"></li>
                <a href="#" class="nav-link">About KLion</a></li>
                <a href="#" class="nav-link">News & Updates</a></li>
                <button type="button" class="btn">
                    <img src="../../assets/Group 1.png" alt="logo" style="width:80px; height:20px;">
                </button>
                <button type="button" class="btn">
                    <img src="../../assets/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ffce7e0ffffe6e1e8a2eceefdfbcfbdf7a1ffe1e8">[email protected]</a>" alt="logo" style="width:20px; height:20px;">
                </button>
            </div>
        </nav>
    </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The presence of element hr within element ul is not permitted in this particular context. Additional errors from this subtree will not be displayed

Here is the code snippet that I have been working on recently: Originally, I had an "hr" tag directly included in my code which worked perfectly but caused a site validation error. So, I made some changes to the code as shown below: <nav> ...

The background-color of a single child within an absolutely positioned element in Chrome may not be displayed if the element has a z-index and overflow scrolling

This test page has been created to showcase the issue: <html> <head> <style> .panel { position: absolute; width: 326px; max-height: 200px; overflow: scroll; z-index: 1000; } .item-container { width: 100%; list-style: none; ...

Menu navigation with animated transitions - Not achieving the desired result

Recently, I posted this question and received a fantastic answer. However, now my client is requesting a hover animation for the navigation items. I started exploring jQuery Spritely as it seemed like the perfect solution. Unfortunately, despite my efforts ...

I need help with creating an AJAX JSON call using Angular. Let me share the JavaScript function that I currently have

When a button is clicked, the function below is called. It retrieves data from a JSON file and stores it if a success message is received. Here is a screenshot of the returned data. My JavaScript function is working correctly, but I am new to Angular and l ...

The mdb navigation bar seems to constantly change its height

Having an issue with the height of my mdb navbar in my Angular app. It randomly flips to a larger size when reloading the page, but returns to normal when I open the developer console in Chrome. Two screenshots show the correct display and the incorrect i ...

An error was encountered: $controllerProvider provider is not recognized within the productsApp

Here is the link to my code: http://plnkr.co/edit/8muxhJmvFiIqRJgzuT0O?p=preview I encountered an error: Uncaught Error: Unknown provider: $controllerProvider from productsApp Additionally, I am unable to view the JSON file in the console. index.html ...

Experiencing difficulties with setting the width of owl carousel

Here is the HTML code snippet: <div class="row"> <div class="col-lg-7 col-sm-6"> <div class="owl-carousel" id="homeCarousel"> <div class="item"> <img src="images/brela.jpg" alt="brela makarska"> </d ...

Finding the Location of the Parent Page within an iFrame

When attempting to retrieve the Parent screen position using the code below, I am consistently receiving a value of 0: window.parent.$(document).scrollTop() ...

How can I align my checkboxes horizontally with a set number using bootstrap?

Is there a way to align my checkboxes next to each other in columns of 5, rather than being stacked vertically? The current layout looks like this: Checkboxes vertical I would like the checkboxes to appear like this: [x] label [x] label [x] label [x] l ...

Fetching the jquery variable within an HTML document: A step-by-step guide

Here is the content of my check.js JavaScript file, which includes a function: function fun2(userid) { $.ajax({ type: 'POST', url: 'ex.php', data: {userid: userid}, success: function (data) { ...

The issue of Angular, ng-ckeditor, and the problematic editor-destroy-iframe bug

This particular post pertains to [email protected] and is filled with information on [email protected]. Despite finding similar questions on SO, I am convinced that this remains an unresolved issue. Please refrain from marking this post as a dup ...

Looking to organize, refine, and establish a default value with the help of rxjs

In my Angular application, I have an observable that is linked to a reactive forms dropdown control. My goal is to filter, sort, and display the default value. I've created two separate implementations - one for filtering and sorting without displayin ...

Smoothly scrolling to an element within a nested div with a scrollable area using JQuery

I need to smoothly scroll down to a specific div that is located within another div containing scrollbars. var div_terms = $('#div_terms').offset(); $("#scroll_to_accept").click(function (){ //$(this).animate(function(){ ...

Multiple Class Changing Effects: Hover, Fade, Toggle

I have a simple yet complex problem that I am trying to solve. I want to create links that fade in upon mouseover and fade out when the mouse moves away. Simultaneously, I want an image to slide in from the left while hovering over the links. I have manage ...

What could be causing the background-color in Chrome Dev Tools to appear faded instead of crossed out?

I have a few queries to share. I noticed that the background of my menu bar is white, but when I remove a specific class from an element further down on the page, the menu bar turns black. I am perplexed as to why changing the style of an HTML section elem ...

Place the background image of the parent element relative to the child element

I am struggling to position the background image of <body> relative to one specific child <div>. <body> <div>content</div> <-- place background image of body relative to this div <div>other content</ ...

The Angular CLI seems to be having trouble locating modules that are clearly present within the workspace

After deleting a component and recreating it with the same name and folder structure using the CLI, I encountered an error. The CLI began throwing errors stating it couldn't find modules that were clearly present and untouched. These modules are simpl ...

Is there a way to make a div collapse to the left instead of collapsing to the top using Bootstrap 4? (with animation)

Is it possible to use Bootstrap 4 to collapse a div with a sidebar menu to the left without extensive changes? I'm hoping to achieve this without having to write my own JS or rely on external scripts. So far, I've been exploring the bootstrap co ...

Tips on vertically aligning a div using Bootstrap

I'm looking to vertically align a card in the center <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorig ...

Other options for setting a background image in HTML emails aside from utilizing the background-img URL and avoiding the use of divs

I am struggling with creating the header section for an HTML email that is currently under construction. I am using background-img url for the image with content overlay, but unfortunately Outlook 2007, 2010, and 2016 do not support background-images on ta ...