Tips for aligning a logo in the center of a navigation bar

I'm struggling to center a logo within the navigation bar of a website I am designing. Despite my attempts, I have not been successful in achieving the desired result. My goal is to have the logo positioned in the middle of the navigation bar, with other elements appearing on either side of it. Currently, everything including the logo is evenly spaced out, resulting in it being off-center. Any guidance or suggestions would be greatly appreciated.

HTML

 <nav class="main-nav-outer" id="test">
        <div class="container">
            <ul class="main-nav">
                <li><a href="#home">Home</a></li>
                <li><a href="#service">Services</a></li>
                <li><a href="#SeasonalSpecials">Seasonal Specials</a></li>
                <li class="small-logo">
                    <a href="#header"><img src="img/logo.png" alt=""></a>
                </li>
                <li><a href="#Products">Products</a></li>
                <li><a href="#team">Team</a></li>
                <li><a href="#contactbanner">Contact</a></li>
            </ul>
            <a class="res-nav_click" href="#"><i class="fa-bars"></i></a>
        </div>
    </nav>

CSS

    .main-nav-outer{
    padding:0px;
    border-bottom:1px solid #dddddd;
    box-shadow:0 4px 5px -3px #ececec;
    position:relative;
    background:#fff;
}
.main-nav{
    text-align:center;
    margin:10px 0 0px;
    padding:0;
    list-style:none;
}
.main-nav li{
    display:inline;
    margin:0 1px;
}
.main-nav li a{
    display:inline-block;
    color:#222222;
    text-transform:uppercase;
    font-family: 'Montserrat', sans-serif;
    text-decoration: none;
    line-height:20px;
    margin:17px 32px;
    transition:all 0.3s ease-in-out;
    -moz-transition:all 0.3s ease-in-out;
    -webkit-transition:all 0.3s ease-in-out;
}

.main-nav li a:hover{
    text-decoration:none;
    color: #ec5020;
}

.small-logo{
    padding:0 32px;
  margin: 0;
}

.main-section{
    padding:20px 0 110px;
}

Answer №1

Consider incorporating Bootstrap to achieve a design similar to this:

<nav class="main-nav-outer" id="test">
        <div class="container">
            <ul class="main-nav">
                <div class="row">
                    <div class="col-xs-5">
                        <li><a href="#home">Home</a></li>
                        <li><a href="#service">Services</a></li>
                        <li><a href="#SeasonalSpecials">Seasonal Specials</a></li>
                    </div>
                    <div class="col-xs-2">
                        <li class="small-logo">
                            <a href="#header"><img src="img/logo.png" alt=""></a>
                        </li>
                    </div>
                    <div class="col-xs-5">
                        <li><a href="#Products">Products</a></li>
                        <li><a href="#team">Team</a></li>
                        <li><a href="#contactbanner">Contact</a></li>
                    </div>
                </div>
            </ul>
            <a class="res-nav_click" href="#"><i class="fa-bars"></i></a>
        </div>
    </nav>

To style the navigation links, update your CSS with the following code:

.main-nav li a {
            display: inline-block;
            color: #222222;
            text-transform: uppercase;
            font-family: 'Montserrat', sans-serif;
            text-decoration: none;
            line-height: 20px;
            margin: 17px 10px;
            transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -webkit-transition: all 0.3s ease-in-out;
        }

Answer №2

HTML:

<nav class="main-nav-outer" id="test">
    <div class="container">
        <ul class="main-nav">
            <li><a href="#home">Home</a></li>
            <li><a href="#service">Services</a></li>
            <li><a href="#SeasonalSpecials">Seasonal Specials</a></li>
            <li class="small-logo">
                <a href="#header"><img src="img/logo.png" alt=""></a>
            </li>
            <li><a href="#Products">Products</a></li>
            <li><a href="#team">Team</a></li>
            <li><a href="#contactbanner">Contact</a></li>
        </ul>
        <a class="res-nav_click" href="#"><i class="fa-bars"></i></a>
    </div>
</nav>

CSS:

.main-nav-outer{
    padding:0px;
    border-bottom:1px solid #dddddd;
    box-shadow:0 4px 5px -3px #ececec;
    position:relative;
    background:#fff;
}
.main-nav{
    margin-left:auto;
    margin-right: auto;
    list-style:none;
}
.main-nav li{
    display:inline;
}
.main-nav li a{
    display:inline-block;
    color:#222222;
    text-transform:uppercase;
    font-family: 'Montserrat', sans-serif;
    text-decoration: none;
    line-height:20px;
    margin:17px 32px;
    transition:all 0.3s ease-in-out;
    -moz-transition:all 0.3s ease-in-out;
    -webkit-transition:all 0.3s ease-in-out;
}

.main-nav li a:hover{
    text-decoration:none;
    color: #ec5020;
}

.small-logo{
    padding:0 32px;
}

.main-section{
    padding:20px 0 110px;
}

Bootply

Answer №3

Give this a shot:

.navbar-brand {
  float: left;
  text-align: center;
  width: 378px;
}
.navbar-brand span {
  margin: 0 auto;
  text-align: center;
  color:green;
} 
.navbar-nav li a{
    display:inline-block;
    color:#222222;
    text-transform:uppercase;
    font-family: 'Montserrat', sans-serif;
    text-decoration: none;
    line-height:20px;
    transition:all 0.3s ease-in-out;
    -moz-transition:all 0.3s ease-in-out;
    -webkit-transition:all 0.3s ease-in-out;
}
      
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<nav class="navbar navbar-fixed-top navbar-custom ">
  <div class="container" >
<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>
  <a class="navbar-brand visible-xs" href="#"><span class="navbar-logo">STACK OVERFLOW</span></a>
</div>
<div class="collapse navbar-collapse">
  <ul class="nav navbar-nav navbar-left">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">Menu Item 1</a></li>
<li><a href="#contact">Menu Item 2</a></li>

  </ul>
  <a class="navbar-brand hidden-xs text-center" href="#"><span class="navbar-logo">STACK OVERFLOW</span></a>
  <ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">Menu Item 1</a></li>

  </ul>
</div>
  </div>
</nav>

Experience the outcome by clicking on Expand snippet.

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 concept of CSS "preload" animation

When working with CSS, I encountered an issue with lag while loading 24 different mask images for a transition effect. To address this, I tried using a div called "preload" to cache the images and prevent lag on playback: <div class='trans' s ...

Creating a custom design for ng-bootstrap accordion using CSS styling

I've encountered an issue with my Angular 2 component that utilizes an accordion from ng-bootstrap. While the functionality works perfectly, I'm facing a problem with applying custom styles using the .card, .card-header, and .card-block classes o ...

Does the onChange event fire when the value is modified by the parent element?

let [number, set_number] = useState({x: 1}); <ChildComponent number={number} onUpdate={onUpdateFunction} </ChildComponent> set_number({x: 2}) After running set_number({x: 2}), will this action prompt the execution of onUpdateFunction refere ...

Tips on utilizing jQuery or JavaScript to efficiently filter out outcomes exceeding a specified range

<input type="range" name="rangeInput" min="100000" max="750000" onchange="updateTextInput(this.value);"> Displayed above is the slider code that provides a value output below. <div id="sliderValue"> <p>Max Value £</p> <input t ...

how do I modify my JavaScript code to achieve the desired outcome

How can I program a button to disable after being pressed 10 times in less than a minute, but continue counting if not pressed for 1 minute? function buttonClicked() { if (totalCount + accCounter > 9) { document.getElementById("btn").disabled = ...

conceal a division beneath a YouTube video frame upon clicking

I need to hide the 'div .blind' element when a YouTube video (inside 'div #player') is clicked. How can I achieve this? Here's an example: JS: ... var player; function onYouTubeIframeAPIReady() { player = new YT.Player('pl ...

Looking to generate an HTML table using JavaScript?

Similar Question: Create HTML table from a Javascript array I have received an array that looks like this var univArray = new Array( {name: "Stanford University", nick: "Stanford", ownership: "private", sys: "n/a", SATh: 1550, SATl: 1360, tui ...

Having difficulty handling text overflow in Angular4 and HTML

I'm facing an issue with displaying a very large text in a table. Despite trying various attributes such as - { text-overflow: clip; } { text-overflow: ellipsis; } { text-overflow: ellipsis-word; } { text-overflow: "---"; } { text-overflow: ellip ...

Using Google Script Code in Sheet to input a key and click on the submission button

Is there a way to enable using the Enter key in addition to clicking the submit button to input data and save it to a cell? I'm having trouble getting my current code to work. Any suggestions on how to modify it? <script> var itemBox = document ...

Ways to update the color of the mat-dialog-title using the material theme

Currently, I am utilizing the Angular Material Dialog and have been attempting to dynamically change the title color of the dialog based on the material theme. <h1 mat-dialog-title color="primary">{{ title }}</h1> Even though setting ...

Div not centered after translation by 50% on the Y-axis

My HTML and body have a height of 100vh. Inside my body, I have a square that is 100px by 100px. When I apply top: 50% to the div, it moves down 50%. But when I apply translateY(50%) to the div, it does not move down 50%. Why is this? Please note that y ...

Is the HTML Page loading before the AJAX call is made?

On my HTML Page, I have a button tag that looks like this: <button ng-hide="alreadyFreinds()" type="button" class="btn btn-primary btn-lg">Friend</button> However, when attempting to access certain parts of the alreadyFriends function shown b ...

ASP.Net & Ajax Fusion Login Interface

I am encountering an issue while creating a login page with HTML, AJAX, and ASP.NET. The data is being passed to the AJAX function successfully, but when I debug the ASP page, the username and password are showing up as NULL. The purpose of the code is to ...

Animation Effects in Opera and Internet Explorer

Just unveiled my latest project, CSSload.net - an awesome tool for generating CSS spinners and bars. The animations are running smoothly on Firefox and Webkit browsers. Curious if anyone has tips on animating elements like this in Opera and IE? ...

How can I determine the specific quantity of XPATH links with unique identifiers in Selenium?

Seeking automation with Python3 and selenium to streamline searches on a public information site. The process involves entering a person's name, selecting the desired spelling (with or without accents), navigating through a list of lawsuits, and acces ...

Modify text by adjusting text color based on the contrast with the background color using knockout databinding

I am working with a table that contains data from my database: Here is the ViewModel structure: function alertViewModel(i) { var self = this; self.Id = ko.observable(i.Id); self.AlertType = ko.observable(i.AlertType); self.Category = ko.observab ...

Conceal the div based on the criteria

I need an inline solution for this issue: <div id="xy<%=statusCount%>" style="margin-top: 50px;display:${<%= statusCount %>!=0 ? 'none' : ''};" class="XYZ"> This code is causing an error ...

Transforming a dynamic HTML layout into a non-responsive one: "RESPONSIVE NO MORE"

I'm currently working with an HTML document that has a responsive design. However, I now need to make it non-responsive. Can someone advise me on the most efficient and fastest way to do this? I attempted using min-width for both html and body, but ...

Tips for resolving the Firefox display problem with input[type="file"] using CSS

After researching articles, it became clear to me that input[type="file"] displays differently across various web browsers. I am in need of a simple solution using only CSS to address this issue as I only require adjusting the width of the element. The w ...

Guide to adding a tag in front of a text in HTML with Python

Searching for all the text within the html document and wishing to incorporate a span tag that contains additional information about each text as shown below def recursiveChildren(x): if "childGenerator" in dir(x): for child in x.childGenerator( ...