Is it necessary to have uniform spacing between links in a responsive navigation menu?

I am attempting to create a horizontal menu navigation system. I have multiple links in the navigation, and my goal is to evenly space them horizontally.

Is there a way to achieve uniform spacing between links in a horizontal menu?

HTML:

    <div id="header">
    <div class="secondary-navigation">
        <div itemscope itemtype="http://schema.org/SiteNavigationElement">
            <nav id="navigation">
            <ul id="menu-main" class="menu">
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             <li class="menu-item"><a href="" title="Link" itemprop="url">Link</a></li>
             </ul>
             <a href="#" id="pull">Menu</a>
             </nav>
        </div>
    </div>
    </div>

CSS:

#header {
    position: relative;
    float: left;
    padding: 0 0 0 0;
    clear: both;
}

/*-----------------------------------------------
/* Header navigation
/*---------------------------------------------*/
.secondary-navigation {
    display: block;
    width: 100%;
    float: left;
}
.secondary-navigation a {
    vertical-align: top;
    color: #F1F1F1;
    font-weight: bold;
    margin-top: 8px;
    margin-bottom: 4px;
    line-height:18px;
    font-size: 15px;
    border-bottom: 2px solid #333888;
}

.secondary-navigation a:hover, .secondary-navigation .sfHover {
     color: #F1F1F1;
     border-bottom: 2px solid #F1F1F1;
      }
.secondary-navigation li li a { line-height: 1 }
.secondary-navigation a .sub {
    font-size: 12px;
    font-weight: normal;
    color: #CFCFCF;
    text-transform: none;
}
.menu-item-has-children > a:after {
    content: "▼";
    font-size: 10px;
    color: #F1F1F1;
    position: absolute;
    right: 12px;
    top: 22px;
}
.footer-navigation .menu-item-has-children > a:after { display: none }
.sub-menu .menu-item-has-children>a:after {
    right: 0;
    top: 17px;
}
.menu .current-menu-item > a { background: #fff }
.menu .current-menu-item > a:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 1px;
    background: #fff;
    bottom: 0px;
    left: 0;
    z-index: 1;
}
#navigation {
    margin: 0 auto;
    font-size: 13px;
    width: 100%;
    float: left;
}
#navigation ul {
    margin: 0 auto;
    list-style: none;  
}
#navigation .menu { float: left; }
#navigation ul li {
    float: left;
    position: relative;
    margin-left: 0;
}
#navigation > ul li:first-child a {  }
#navigation > ul li:last-child a { border-right: 0 }
#navigation ul .header-search { float: right }
#navigation > ul > li:last-child { border-right: none }
#navigation ul li a, #navigation ul li a:link, #navigation ul li a:visited { display: block }
#navigation > ul > .current a {
    background: transparent;
    color: #555 !important;
}
#navigation li:hover ul, #navigation li li:hover ul, #navigation li li li:hover ul, #navigation li li li li:hover ul {
    opacity: 1;
    left: -228px;
    top: 0;
}
#navigation ul ul {
    position: absolute;
    width: 226px;
    z-index: 400;
    font-size: 12px;
    color: #333888;
    border: 1px solid #F1F1F1;
    background: #FFFFFF;
    padding: 0;
}
#navigation ul ul li {
    margin-left: 0;
    padding: 0 10%;
    width: 80%;
    color: #333;
}
#navigation ul ul li:hover { background: #F1F1F1 }
#navigation ul ul a, #navigation ul ul a:link, #navigation ul ul a:visited {
    padding: 12px 0;
    position: relative;
    border-left: 0;
    background: transparent;
    border-right: 0;
    text-transform: none;
    line-height: 1.4;
    margin-right: 0;
    min-height: 100%;
}
#navigation ul ul li:last-child a { border-bottom: none }
#navigation ul ul {
    opacity: 0;
    left: -999em;
}
#navigation ul li:hover ul {
    left: -1px;
    opacity: 1;
    top: 81px;
}
#navigation ul ul li:hover ul {
    top: -1px;
    left: -228px;
    padding-top: 0;
}
#navigation ul ul ul:after { border-color: transparent }

I experimented with a method similar to this example, but it did not yield the desired result for me.

Answer №1

You have the option to utilize either justify-content: space-between or justify-content: space-around with the flexbox property

ul {
  display: flex;
  justify-content: space-between;
  border: 1px solid black;
  list-style-type: none;
  padding: 10px;
  margin: 0;
}
<ul>
  <li>Random Link</li>
  <li>Random Link</li>
  <li>Random Link</li>
  <li>Random Link</li>
</ul>

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

Arrange three images both vertically and horizontally at the center of the page

I am facing an issue with aligning a button and 2 images in a row on my website. Currently, this is how it looks: https://i.stack.imgur.com/yrQB6.png Here is the HTML code I am using: <div class="row text-center"> <div class="col-md-12"> ...

Getting the css property scaleX with JQuery is as simple as executing the

I am struggling to print out the properties of a specific div element using jQuery. My goal is to have the different css properties displayed in an information panel on the screen. Currently, I am facing difficulties trying to show scaleX. Here is my curr ...

Error in CSS Header - Position Shifts when Hovered Over

UPDATED HEADER HTML/CSS I am currently working on the header section of my website at . I encountered a bug where, upon hovering over the links in the header from right to left, the positions of the links become disorganized. I am unsure of what might be ...

Mastering the art of flawlessly executing kerning-generated code

I am facing a problem while implementing logotext with kerning technique in the <header> element. I found a useful tool made by Mr. Andrew which can be accessed through this link. Before making any modifications, I had the following code in the heade ...

Fluid Grid System with columns of specific dimensions

Recently delving into the world of Foundation Framework, I've just begun utilizing it for my projects. My current task involves crafting a responsive design with the help of the Foundation Grid system. Specifically, I've set up a grid layout for ...

Tips for preventing vertical spaces between table header cells in material-UI

Is there a way to remove the vertical gaps between header cells in the MUI table? To see an example of the issue, check out this codesandbox link: https://codesandbox.io/s/mui-material-table-sticky-header-forked-euilo3?file=/tsconfig.json I have attempte ...

Differences between -webkit- and -moz-transition

My website uses CSS3 transitions and I have noticed that the -webkit- prefix works, but the -moz- prefix does not seem to be working. This is the CSS code I am using: article {z-index: 2; float: left; overflow: hidden; position: relative; -webkit-transit ...

How can I shift the button's location within a pop-up in Ionic 1?

enter image description here I am struggling to make the button green underneath the three other buttons. Can someone please assist me with this? Here is my code: $scope.showIntroductionPage = function(childs){ if(childs == 0){ var myPopup = $io ...

What is the best way to position three DIVs next to each other within another DIV while aligning the last DIV to the right?

I need help formatting a simple list item with three DIVs. The first DIV should be left justified, the second should be able to grow as needed, and the third should be right justified. I currently have them stacked side by side, but can't get the last ...

URL to section of website without the navigation bar portion

I am trying to solve a problem with creating a link that will take me to a specific part of the page while taking into account the height of the navbar. The issue is that since the navbar is fixed to the top with a solid color, it ends up covering part of ...

Tips for handling numerous buttons in ionic?

I'm currently working on an app that includes surveys. In this app, users are required to answer by selecting either the Yes or No button. The desired behavior is for the chosen button to turn blue once clicked, while the other button should maintain ...

exploring numerous boxes in an engaging and educational tutorial

Explaining this in the title was a bit tricky, but what I want to create is an interactive tutorial. In this tutorial, the user will click on an area or product they want to clean or use for cleaning. After clicking, another box with relevant information w ...

Creating a dynamic collection of N triangles in a container using CSS

In my current project, I am developing an Electron+Vue application that features a grid-styled map. Each cell on the map represents a room, and I want to indicate walls within these cells. Specifically, for directions North, South, East, and West, I can us ...

VSCODE's intellisense feature seems to be ignoring CSS code within JSX files

I've been puzzling over why Visual Studio Code isn't recognizing CSS syntax inside JSX files. While I'm typing, CSS IntelliSense doesn't provide suggestions for CSS - only Emmet suggestions.https://i.stack.imgur.com/FegYO.png Despite t ...

How can you access a sibling of the parent element of the current element in Jquery?

I'm working on an HTML project where I have a select field. Depending on the option selected, I need to update the price field with the corresponding price fetched using Ajax. Additionally, I want to be able to input multiple rows by clicking on the ...

The entire framework remains concealed as the anchor component becomes immeasurable

Within a fixed-width paragraph, I have an anchor tag. The CSS for the p tag includes the properties text-overflow: ellipsis and overflow:hidden. However, when the anchor tag's content overflows (e.g., it contains a long string), the right outline is n ...

"Interactive feature allowing users to edit and view the most recently inserted HTML

My approach involves using a contenteditable div as an input field for entering text and inserting icons through a button that adds small HTML pictures within the text. Everything works fine when the text is narrower than the contenteditable field. Howev ...

When we typically scroll down the page, the next section should automatically bring us back to the top of the page

When we scroll down the page, the next section should automatically bring us back to the top of the page without having to use the mouse wheel. .bg1 { background-color: #C5876F; height: 1000px; } .bg2 { background-color: #7882BB; height: 1000px; } .bg3 ...

Identify and mark labels when hovering over them

Hello everyone! I'm completely new to this, so please be gentle :). Apologies in advance if my terminology is off. I have zero experience with HTML, but I landed here from working with FileMaker. Currently, I am developing a FileMaker database for my ...

Arrange the labels and input fields within nested elements in a synchronized manner

My data is structured semantically as shown below: <div class="inputs"> <div class="top"> <h4>Top</h4> <label for="top-1">Label 1</label> <input id="top- ...