What is the best way to center my navbar logo and have the navigation links encapsulate it on either side?

I am looking to achieve a design where my navbar brand is centered with the navigation links positioned on the left and right of it. When the screen size reaches md, I want the nav links to disappear into a burger menu while still keeping the nav brand visible at the top center.

    <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
        <div class="container">
            <div class="navbar-brand"><h2>Name</h2></div>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#burger"><span class="navbar-toggler-icon"></span></button>

            <div class="collapse navbar-collapse" id="burger">
                <ul class="navbar-nav mx-auto">
                    <li class="nav-item px-5">
                        <a href="#python" class="nav-link" style="color: white;"><h2>Python</h2></a>
                    </li>
                    <li class="nav-item px-5">
                        <a href="#html&css" class="nav-link" style="color: white;"><h2>Html&Css</h2></a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

This is the desired layout: Visual Reference

Answer №1

HTML


<h1 class="text-center">Center Navbar Brand logo</h1>


<div class="container">
  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
              <a class="navbar-brand" href="http://disputebills.com"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTvuVbC_1kQQsg8U63u6gWMWuA7W1Ck5t-zkw&usqp=CAU" alt="logo">
      </a>
      </div>
      

      
      <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-left">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
        </ul>
      </div>
      <!--/.nav-collapse -->
    </div>
    <!--/.container-fluid -->
  </nav>
</div>

CSS

.navbar-brand {
  transform: translateX(-50%);
  left: 50%;
  position: absolute;
}


/* DEMO example styles for logo image */
.navbar-brand {
  padding: 0px;
}
.navbar-brand>img {
  height: 100%;
  width: auto;
  padding: 7px 14px;
}

Screenshot

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

Trouble arises when adding HTML elements to a Content Editable Div. Any text inputted after programmatically inserting HTML content will merge with the last HTML tag instead

https://i.sstatic.net/bKIVm.pngI am currently working on a project that involves creating message templates within an app. Users have the ability to add placeholders for fields like names to these templates by clicking a button. They can also remove these ...

top approach for transforming form data into JSON format

My task is to convert data from JSON format in order to send it to a webAPI. I have a popup form called from page1: <form id="popupForm" method="post" class="form-horizontal" action=""> <div class="form-group"> <label class="col-sm-4 c ...

Utilizing CSS variables and HSLA, create a distinctive linear gradient styling

I am encountering an issue with a CSS variable: :root{ --red: hsl(0, 100%, 74%); } Despite defining the variable, it does not work in the following code snippet: .page-wrapper{ background-image: linear-gradient(hsla(var(--red),.6), hsla(var(--red),.6 ...

Display a video modal upon page load, allowing users the option to click a button to reopen the modal

Looking for a way to make a video modal automatically open on page load and allow users to reopen it by clicking a button? Here's a snippet of code that might help you achieve that: HTML <html> <head> <link rel="stylesheet ...

A reliable approach for dynamically altering SVG graphics

It seems like IE10 does not support CSS transformations for SVGs, only attribute transformations. Here is an example: <svg><rect id="myrect" width="200" height="200"></rect></svg> setTimeout(function() { var r = document.getE ...

Ways to replace CSS classes created using makeStyles

To clarify, my development environment is using MUI version 4.12.3. Inside file A, I have a simplified code snippet for a functional component, along with the usage of makeStyles to style a JSX element within the return statement (not displayed here). Ever ...

Ways to limit file types (such as .pdf) in HTML5?

What is the best method to limit file types (such as .pem, .cer) in HTML5? The accept attribute does not completely prevent users from uploading other file types. This particular input field is of type "file". ...

Incorporating a timestamp to a specific cell

I'm currently developing a straightforward web application that involves: Adding table rows to an HTML site. Including a function that inserts the current time into a table cell when clicked. However, I am facing a challenge in finding examples. Wh ...

Embracing the balance of a gradient backdrop

I'm looking to create a gradient background for my page that transitions from light blue in the center to dark blue on the sides in a symmetrical way. I've tried using a linear gradient that goes from left to right, but it doesn't achieve th ...

What is the best way to position three SVG files in the center of a webpage?

I want to combine three separate SVG files to create one single graphic. The first SVG file is a red triangle, the second is a blue circle inside the triangle, and the third is a purple rectangle beneath the triangle with a little space in between. My obje ...

`Considering various factors to alter class pairings`

I have defined a few style classes in my stylesheet as shown below: .left-align{ /* some styles here */ } .right-align{ /* some styles here */ } .validate-error{ /* some styles here */ } Depending on the type of data, I need to align the content ei ...

Container-wrapper unable to contain images, overflowing despite using overflow:hidden property

I am currently working on a unique section for a website that includes a .container-wrapper element consisting of text and multiple images. The container is set to have overflow: hidden; in order to prevent any overflow issues. However, the images within t ...

Is there a way for me to make my image source dynamically switch between 3-4 different images when hovered over?

I'm in the midst of a college project where I'm designing a clothing website. What I'm aiming for is to have the product image on the main feed change between 3-4 images of the same product with a quick transition when a user hovers over it. ...

I am on the hunt for a unique jQuery or CSS selector to resolve a specific problem

I need assistance finding a jQuery or CSS selector for a specific issue. Here is the code snippet: <div class="parent"> <div class="grid1"> <p>grids have also p</p> </div> <div class="grid2"> <p& ...

I'm having difficulties with separators in CSS when I attempt to insert one

Hey there, I've encountered an issue with my separator: #menu li:not(:first-child):before { content: " | "; } Despite this code working, the first li item isn't being separated like the others. This is the current output I'm getting: t ...

Organize the words within HTML elements without considering the tags

My webpage contains buttons that appear as follows: <button>Apple</button> <button>Dog</button> <button>Text</button> <button>Boy</button> <button class='whatNot'>Text</button> <butt ...

Issue with creating a custom YouTube navigation bar positioned above suggested video content

bar image Currently, I am attempting to recreate this navigation bar for my YouTube-inspired project. Although I have successfully made the background of the buttons fade using linear-gradient, I am unsure how to apply the same effect to the text itself. ...

Achieving a sticky scrollbar effect in CSS/JavaScript for scrolling within nested divs

I am trying to create a table with vertical scrolling for the entire table content. Additionally, I need two columns within the table to be scrollable horizontally, but the horizontal scrollbars disappear when the vertical scrollbar is present. How can I k ...

JavaScript array images are not showing when using the img tag

For this module, I am working on creating a flipbook (magazine) using images stored in a JavaScript array. However, I am facing an issue where the images are not loading up properly. Instead of displaying the image, it shows as [object" htmlimageelement]=" ...

benefits of personalizing scroll bars using html and css

Is it possible to change the default scroll bar style to custom scroll bars using just HTML and CSS, without JavaScript or jQuery? Any tips on how to achieve this, or suggestions on best practices? Thank you in advance! ...