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

The img-fluid class is not properly adjusting the height of the image

I'm currently working with Bootstrap 4 and facing a challenge with creating a grid of 4 images - 2 on top and 2 at the bottom. I've applied the img-fluid class, but the image resizing is based solely on width, leading to the height being too larg ...

Adjust the color of text as you scroll

Could you provide guidance on changing the color of fixed texts in specific sections of my portfolio website? Unfortunately, I can't share my lengthy code here, but would greatly appreciate it if you could illustrate with examples. Here's a refer ...

Is it possible to verify .0 with regular expressions?

In my project, I have a field that requires whole numbers only. To validate this, I used a regex validation /^\d{1,3}$/ which successfully validates whole number entry and rejects decimal points starting from .1. However, I encountered an issue where ...

Clickable regions in Internet Explorer 7 that lack a specific width

Is there a way to make the clickable area of links always stretch to the parents container when the parent container does not have a fixed width? For example, check out this JSFiddle. In Firefox, the link stretches with the text and the li tag, but in IE ...

Incorporating the FLEX property into my code has been a challenge as it is not functioning properly on iOS 7 and 8 devices. Does anyone have any tips or suggestions on how to

While utilizing FLEX in my code, I noticed that the output is not what I expected on iOS 7/8 devices. <div className="modal-row"> <div className="col1"> <span>{dict.YourServiceNumber}</span> </div> <div ...

Bringing the Jquery cursor into focus following the addition of an emoji

Looking to add emojis in a contenteditable div but facing an issue with the cursor placement. Here is a DEMO created on codepen.io. The demo includes a tree emoji example where clicking on the emoji adds it to the #text contenteditable div. However, after ...

SB Admin 2 menu with multiple levels does not collapse as expected

I'm in the process of integrating the menu from the sb admin 2 template into my Ruby on Rails application: As I gradually added components to test functionality, I successfully implemented the top and side nav bars. However, I encountered an issue wi ...

Is there a way to adjust the label elevation for a Material UI TextField component?

I am trying to enhance the appearance of a textfield label, but I am facing some challenges with my code. textStyle: { backgroundColor: '#1c1a1a', border: 0, borderRadius: 0, width: 400, height: 66, display: 'flex&a ...

Combining the lower margin of an image with the padding of a container: a step-by-step guide

There are two divs with a 50px padding, making them 100px apart. The top div contains an image floated to the right with paragraphs wrapping around it. The requirements team requests a 20px margin below the image if text flows under it, but no margin if th ...

"Enhance your website with a sleek Bootstrap navigation system featuring dividers and

Need help with creating a Bootstrap nav menu similar to this design made in Photoshop? Wondering about the best way to position the logo and create dividers between menu items like shown in this image. Here's the HTML code currently being used: & ...

Change the text inside a container without losing any associated event listeners using JavaScript or jQuery

Here is the HTML code: <div id="div001"> This is ${Row.1}. <p>${Row.2} explain something else.</p> <p>${Row.3} welcome you. <span>${Hello.World}, this is a new world.</span></p> </div> My objective is ...

Having issues with CSS list hovering functionality in Google Chrome

One of the challenges I'm facing with my HTML list is that when hovering over each list item, the text along with the bullet point should change color. Here's the structure: <ul> <li>A bullet point</li> <li>Another ...

Altering the "src" property of the <script> tag

Can the "src" attribute of a current <script> element be altered using Jquery.attr()? I believed it would be an easy method to enable JSONP functionality, however, I am encountering difficulties in making it operate effectively. ...

linking to a page that shows the user's chosen option from a dropdown menu

One of the challenges I encountered was creating a feature that allows users to share a specific selection from multiple dropdown lists on a page. Essentially, my goal was to enable users to send a link that would direct others to the same page with the ex ...

Material User Interface, MUI, Modal, Back to Top Scroll按钮

After spending some time experimenting with scrollTop and the Dialog component (a fullscreen fixed modal) from Material-ui, I found that I couldn't quite get scrollTop to function properly. Whenever I clicked the "go down" button, it would either retu ...

Switch the display of a div within a ng-template loop using PrimeNg

Working with the PrimeNg picklist, I have encountered a challenge. Here's what's going on: The main focus is on the first row, while the other rows do not have radio buttons (as they are part of incomplete test data). The goal is to show a drop ...

The input field is failing to show up on the screen

I have been working on my React app and experimenting with how to dynamically display input elements based on different screen sizes. To achieve this, I implemented the use of window.innerWidth as shown in the code snippet below: <div className='Tr ...

Employing the power of JavaScript to enable the seamless toggle of an overlay

I have a div named "navbar_menu". On clicking this div, I want the visibility of the div named "nav_overlay" to fade in. Upon another click, I want it to fade back and become invisible again. Currently, I have set the div 'nav_overlay" to have ' ...

Display a DIV element when hovering over another DIV element using CSS or JavaScript without them being directly related as parent and

So I've figured out how to use CSS to show a hidden div when you hover over its parent. But what if the hidden div is not a child of the parent you want to hover on? How do you make it appear then? For example: <div class="field-1"></div> ...

What is the best way to eliminate HTML <li> bullets using codebehind?

When working in codebehind, I often create an HTML list using the following method: HtmlGenericControl list = new HtmlGenericControl("ul"); for (int i = 0; i < 10; i++) { HtmlGenericControl listItem = new HtmlGenericControl("li"); Label textLabel ...