What is the best way to position the logo in the center of the navigation bar, considering there are an unequal number of menu items on each side

As I work on coding a design I found for practice, I am facing the challenge of getting the logo to be centered in the navbar, similar to the layout in the Dribble link below.

View Design on Dribble

The navigation bar has 4 items aligned on the left and only two on the right. Initially, I floated them all to the left but couldn't achieve the desired outcome. So, I decided to try flexbox after coming across this helpful tip on Stack Overflow: Link to Tip

While using flexbox did help position all my navigation items equally, it only works when there is an even number of items in the navbar. Furthermore, I'm contemplating whether it's acceptable to include all these items as normal navigation links rather than buttons. The CSS code I've implemented mirrors the one from the link above, ensuring equal positioning for all nav items, but I'm struggling with centering the logo. Although I believe flexbox offers a simple solution, this project marks my first time working with it.

nav{
  display:flex;
  width:100%;
  height:20%;
  background:#eee;
  align-items:center;
  justify-content:center;
}

nav a {
  text-decoration:none;
  color:black;
  margin: 0 30px;
}

#logo{
  width: 200px;
  height:100%;
  background:rgb(126, 232, 163);
}
<nav>
   <a href="#">Menu icon</a></li>
   <a href="#">Search icon</a></li>
   <a href="plan.html">Plan Your Trip</a></li>
   <a href="experience.html">Experience</a></li>
   <a href="index.html" id="logo">mifestival</a></li>
   <a href="tickets.html">Tickets</a></li>
   <a href="line-up.html">Line-Up</a></li>
</nav>

Answer №1

Let's start by organizing your menu into three separate sections: left side, middle/logo, and right side.

<nav>
    <div class="leftSide">
        <a href="#">Menu icon</a>
        <a href="#">Search icon</a>
        <a href="plan.html">Plan Your Trip</a>
        <a href="experience.html">Experience</a>
    </div>
    <div class="logo">
        <a href="index.html" id="logo">mifestival</a>
    </div>
    <div class="rightSide">
        <a href="tickets.html">Tickets</a>
        <a href="line-up.html">Line-Up</a>
    </div>
</nav>

To style it, we'll include the following CSS:

.leftSide {
    width: calc(50% - 100px);
    display: flex;
    justify-content: center;
}
.rightSide {
    width: calc(50% - 100px);
    display: flex;
    justify-content: center;
}

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

elements that do not adhere to set width constraints

I've successfully arranged elements in my HTML using flexbox to achieve a responsive design for a website. However, I've encountered an issue where the elements do not resize properly. After applying a class of flex to the home-promos div and re ...

Is there a way to create an <a> element so that clicking on it does not update the URL in the address bar?

Within my JSP, there is an anchor tag that looks like this: <a href="patient/tools.do?Id=<%=mp.get("FROM_RANGE") %>"> <%= mp.get("DESCRITPION") %></a>. Whenever I click on the anchor tag, the URL appears in the Address bar. How can ...

scraping information using xpath from the subsequent page

I've been attempting to extract data from a webpage located at , focusing on fund number 26. While I have no trouble retrieving information from the first page (funds number 1-25), I'm facing difficulties with scraping anything from the second p ...

What is the process for extracting the value of a checkbox generated through JavaScript?

I recently came across a helpful post on Stack Overflow that provided sample code demonstrating how to display multiple list of checkboxes dynamically on a dropdown list. The function in the code was exactly what I needed for my webpage. However, I encount ...

Tab knockout binding

I have a section in my HTML with 2 tabs. The default tab is working properly, but when I attempt to switch to the other tab, I encounter an error. Can anyone provide assistance in determining why this error occurs? Here is the HTML code: <ul class="na ...

Customize CKEditor by automatically changing the font family when the page is loaded

How can I change the font-family of CKEditor to Meiryo based on a JavaScript boolean? I attempted this code in my custom JS within an if condition, but it did not successfully change the font-family: config.font_style = { element : 'span&apo ...

"Enhance user experience with jQuery's text expansion and collapse

Figuring out how to collapse and expand text with a button click has been challenging for me. I managed to make the text collapse when the button is clicked, but now I also need it to expand back again. The goal is to have the text initially hidden, then e ...

Searching for a JavaScript tool that offers syntax highlighting capabilities

I have come across some excellent RTE HTML text editors such as jsredaktor, TinyMCE, and FCK Editor, but I am in search of an HTML/JavaScript component that functions similarly to a TEXTAREA with built-in code syntax highlighting. ...

Clicking on the overlay does not close the bootstrap collapsed toggle

I'm currently facing an issue where I need to add a listener that closes the menu when clicked away. The code snippet below shows my attempt at solving this problem: $("body").click(function(e){ var $box1 = $('.navbar-toggle'); var $b ...

The art of perfect alignment: Mastering the positioning of Material-UI Grid

This issue has been resolved Hey there, I'm currently working on a React App with Material-UI and I'm trying to center a Grid item that includes a Card along with two additional Grid items. Below is the relevant code snippet. Although the Cards ...

Transferring Data Between Two Forms

Is there a way to transfer data between two HTML forms? For example, let's say we have two forms: Form 1: Contains a field for name and a submit button. Form 2: Contains fields for name, email, and a submit button. I would like to be able to fill o ...

Is there something I'm overlooking in my image navigation? It doesn't seem to be interactive

Looking for assistance regarding the issue below. I can't seem to make my image clickable, and I'm not sure what's causing this problem. <img src= "makeup.html.jpg" alt= "Make up by Lauren Evans logo" title= "Make ...

Different placeholder text rendered in two text styles

Can an input box placeholder have two different styles? Here's the design I have in mind: https://i.stack.imgur.com/7OH9A.png ...

Create a stylish bottom border exclusively for the text that has been wrapped

My goal is to create an underline that perfectly fits the width of the text on the bottom row, without extending beyond it. The desired effect is shown in Figure 1. Figure 1 Here is the HTML I am currently using: <h2><span class="inline-block"& ...

Do XAML-based apps on Windows 8 provide a noticeable speed advantage over those built with HTML and CSS?

We are in the process of developing a photo-heavy Windows 8 Metro-style app and are concerned about UI performance. While choosing Objective-C over HTML for iOS was an easy decision to achieve the necessary UI performance, we are unsure about the speed com ...

I do not prefer output as my optimal choice

My preference is to create drill down buttons rather than focusing on output. Currently, the output appears as: The content of index.html is as follows: <html>  <head> <script type="text/javascript" src="http://ajax.googleapis.com/ ...

Tips on how to customize an HTML form submission appearance

Take a look at my file upload form below: <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="filetoupload" id="filetoupload" onchange="this.form.submit();"> </form> I am trying to figure out ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

Safari's problem with CSS transitions

This issue is specific to Safari, as it has been tested and works fine in Chrome, Opera, and Firefox. Upon hovering over a certain div (1), a child div (2) slides out by adjusting the left property. However, the child elements (buttons) within the second ...

Excessive text overflowing in a chat interface can be resolved through CSS styling

After conducting a thorough search, it appears that very few individuals are taking this important element into consideration. I currently have a chat interface set up with a div element containing a ul, which then houses li elements that contain p element ...