The aligning property "justify-content: space around" does not behave as expected on a line and does not provide the desired spacing

Below is the HTML code I am working on:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Lawyers' office in Paris 8</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <style>
      @import url("https://fonts.googleapis.com/css2?family=Inter&family=Nunito+Sans:wght@300&display=swap");
    </style>

    <header class="header">
      <div class="logo">
        <img
          src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/Logo-JDB.png.webp"
          alt="logo"
          height="123px"
        />
      </div>
      <div class="ul">
        <ul class="list-1">
          <li>
            <img
              src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/enveloppe-icon.png"
              alt="envelope-logo"
              height="16px"
            />
          </li>
          <li><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c2f2322382d2f380c26282e2d3a232f2d383f622f2321">[email protected]</a></li>
          <li>|</li>
          <li>
            <img
              src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/phone-icon.png"
              alt="phone icon"
              height="16px"
            />
          </li>
          <li>+33 1 42 56 96 96</li>
.....

And this is my CSS styling:

body {
  font-family: "Inter", sans-serif;
  margin: 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: aqua;
  top: 0;
  left: 0;
  right: 0;
}

.logo {
  margin-left: 90px;
}

.list-1,
.list-2 {
  list-style: none;
  display: flex;
  justify-content: space-around;
  margin: 0;
}

I am trying to recreate a website similar to

You can view my progress so far here: click here

However, I encountered an issue highlighted in the following code snippet:

.list-1,
.list-2 {
  list-style: none;
  display: flex;
  justify-content: space-around;
  margin: 0;

The problem is that even though the "space-around" property is applied, it doesn't produce the desired result on the second line. Here is a visual representation of the issue:

Problem

I'm puzzled as to why the spacing effect is not consistent across both lines. My intention is to have equal spacing between words for better alignment with the original website layout.

Your insights and suggestions would be greatly appreciated. Thank you!

Answer №1

When there isn't enough horizontal space available, your li elements may end up crowded together with no room between them. To prevent this issue, consider adding some left and/or right padding to create a minimum distance between the li items:

body {
  font-family: "Inter", sans-serif;
  margin: 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: aqua;
  top: 0;
  left: 0;
  right: 0;
}

.logo {
  margin-left: 90px;
}

.list-1,
.list-2 {
  list-style: none;
  display: flex;
  justify-content: space-around;
  margin: 0;
}
.list-2 li {
  padding: 0 5px;
}
.list-2 li:first-of-type {
  padding-left: 0;
}
.list-2 li:last-of-type {
  padding-right: 0;
}
<style>
  @import url("https://fonts.googleapis.com/css2?family=Inter&family=Nunito+Sans:wght@300&display=swap");
</style>

<header class="header">
  <div class="logo">
    <img src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/Logo-JDB.png.webp" alt="logo" height="123px" />
  </div>
  <div class="ul">
    <ul class="list-1">
      <li>
        <img src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/enveloppe-icon.png" alt="enveloppe-logo" height="16px" />
      </li>
      <li><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32515d5c465351467258565053445d515346411c515d5f">[email protected]</a></li>
      <li>|</li>
      <li>
        <img src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/phone-icon.png" alt="phone icon" height="16px" />
      </li>
      <li>+33 1 42 56 96 96</li>
      <li>|</li>
      <li>
        <img src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/window-icon.png" alt="window icon" height="16px" />
      </li>
      <li>Devis gratuit</li>
      <li>|</li>
    </ul>

    <ul class="list-2">
      <li>ACCUEIL</li>
      <li>COMPÉTENCES</li>
      <li>EQUIPE</li>
      <li>PRESTATIONS</li>
      <li>PUBLICATIONS</li>
      <li>CONTACT</li>
      <li>
        <img src="/Users/jeandizian/Documents/Code/Site-avocats/Assets/Imgs/Magnifying-glass-icon.png" alt="Magnifying glass icon" height="16px" />
      </li>
    </ul>
  </div>
</header>

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

What are the steps to gather user data and generate a roster of individuals currently online?

I am currently working on a way to gather information about the users who are currently logged into my website. Here's how it works: When a user enters my website, they have the option to choose a nickname using an input box. Then, there are five diff ...

Utilize Bootstrap's custom validation exclusively on fields that are invalid

Exploring Bootstrap features has led me to wonder if there's a straightforward method to change the styling of a field specifically when it is considered invalid. <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" ...

Issues have arisen with the @keydown.ctrl and @keyup.ctrl event modifiers in Vue.js, as they are not properly responding

I have a project in VueJS where I need to implement a custom context menu that will pop up when the user hovers over specific elements on the page. This context menu is dynamic, meaning it changes as the user moves between different items. If the user hold ...

Can you please provide me with detailed instructions on how to use the radio button?

As someone who isn't a professional coder, I dabble in creating code for fun. Right now, I'm working on a roleplay project on a website where each character has a designated "space" to input HTML and CSS code as a template. I've stumbled upo ...

Incorporating an HTML file into a DIV container while also displaying menu links

I am facing a major challenge with what I recognize as a relatively simple issue for experts. As someone who is still learning, I am struggling to create menu links that load an HTML file into a specific DIV. Despite my efforts, the content keeps loading i ...

unwelcome tab spacing in CSS

I am facing an issue with unwanted spacing in my lists. I have a code that generates three-column lists, each containing about eight rows. However, the first list item of the last row is causing an unwanted space. It seems to shift entirely to the next col ...

Generate a dynamic image using CSS and either a div or a span tag

My image is intricately carved into several slices. You can view it here <!--Force IE6 into quirks mode with this comment tag--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.d ...

Is it feasible to combine border-radius with a gradient border-image?

I'm trying to style an input field with a rounded border using the border-radius property, and also add a gradient to that border. Despite successfully creating both the gradient and rounded corners separately, I am unable to make them work together. ...

Comparison between Bootstrap 4 and Firefox Preload Error

Hello fellow front end developers who are experiencing an issue with CSS preload in Firefox versions above 74.0. I have encountered a problem with the following code snippet: <link rel='preload' as='style' onload="this.onload=null; ...

Using Material UI, I have styled a typography element and a button to appear on the

Struggling to position a button and a <Typography> element side by side: Here's what I currently have: <Grid item lg={12} md={12} sm={12} xs={12} className={classes.register}> <Typography noWrap className={classes.typoText} varian ...

JavaScript has encountered a syntax error

When working on an animation in javascript, I encountered a problem that I can't seem to identify. I am attempting to make the pan function work with the "mover" function, but it seems like either I am not using the properties correctly within the "tr ...

iOS is not receiving JSON data in the response headers

I am currently utilizing the CocoaHTTPServer for establishing my server connection. However, I encountered an issue with retrieving JSON data in the header file of my HTML page (web client). Here is the code snippet : HTML Page : endAPSession: funct ...

How can white space be maintained using <select> and <V-for> in Vue.js?

Using select and v-for to display values can be tricky when dealing with white space, such as "a a - ". Sadly, most of the white space gets removed when the values are shown and returned to the backend. Here is the code snippet illustrating the i ...

Is an audio player/playlist necessary for showcasing a mix engineer's skills in their

As a newcomer to the world of web development with some background knowledge from school, I work as a mix engineer and have created a portfolio website. Previously, I utilized Soundcloud and Spotify's API to showcase my mixes/songs, but the external J ...

Preserve the video's aspect ratio within a fixed height and width layout by utilizing CSS styling

I am currently in the process of developing a web application with a fixed height layout that does not utilize flexbox and is also limited by width constraints. My goal is to divide the screen in half both vertically and horizontally, around 50% for each ...

The icons in webviews on mobile apps (iOS and Android) fail to render correctly

My font icons are behaving inconsistently on webkit-based mobile browsers when used on mobile devices. When hovering over the span on a desktop browser, the icon properly fills its container: However, when hovering over the span on a mobile device, the i ...

What would cause this to result in a blank array?

I have a main component that contains multiple sub-components, which I navigate between by clicking on different elements. These sub-components are all Vue files. What I am trying to achieve is to dynamically highlight the active component when it is bein ...

"Create a div element with resizable capabilities, similar to a

Is it possible to resize elements like divs in browsers without using jQuery or other libraries like draggable or resizable? I know text-areas can be resized by default, but I'm curious if this functionality can be extended to other elements through p ...

Having issues with mouse hover not functioning on button in internet explorer 8?

Currently, I am working with asp.net mvc4 and encountering an issue where the button's color does not change when hovered over. The default blue focus always remains on the button. Can someone assist me in resolving this problem? I am using Internet E ...

What is the best way to retrieve the unique identifier of dynamically created divs and showcase a message based on that identifier?

Is it possible to retrieve the id of a dynamically generated div and show a unique message when each div is clicked in the code snippet found at this link? function get_random_color() { var letters = '0123456789ABCDEF'.split(''); ...