Inconsistencies in spacing among flex items with flexbox styling

https://i.sstatic.net/oT9dgpaA.png NavBar.js

import React from "react";
import ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';
import './NavBar.css';




function NavBar() {
  const heading = 'first heading'

  let list = ['About Us', 'Career Page', 'Resources']

  const BuildList =  () => { 
    return(
      <>
      <div className = 'nav-container'>
      <div className='logo-container'> Logo Container</div>
        <div className='nav-content-container'>
        </div>
        <div className="navbar-primary-menu">
          { list.map((key) => (<div className='navbar-primary-menu-items' key={key}> {key} </div>)) }
        </div>
      <div className="search-container">
      <svg className='search-icon' xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="80" height="80" viewBox="0 0 48 48">
<path fill="#616161" d="M34.6 28.1H38.6V45.1H34.6z" transform="rotate(-45.001 36.586 36.587)"></path><path fill="#616161" d="M20 4A16 16 0 1 0 20 36A16 16 0 1 0 20 4Z"></path><path fill="#37474F" d="M36.2 32.1H40.2V44.400000000000006H36.2z" transform="rotate(-45.001 38.24 38.24)"></path><path fill="#64B5F6" d="M20 7A13 13 0 1 0 20 33A13 13 0 1 0 20 7Z"></path><path fill="#BBDEFB" d="M26.9,14.2c-1.7-2-4.2-3.2-6.9-3.2s-5.2,1.2-6.9,3.2c-0.4,0.4-0.3,1.1,0.1,1.4c0.4,0.4,1.1,...
        <input className='input-field' type='text'></input>
       </div>
      </div> 
      </>
    );
  };
  // const element = <ul> <li>Hello there</li></ul>

  return(
    <div>
      <BuildList/>
    </div>
  );
}


export default NavBar

NavBar.css

.nav-container {
  display: flex;
  background: cyan;
  justify-content: space-between;
  align-items: center;
  border: 2px solid black;
  
  width: 100%;
  gap: 10px
}

.list {
  list-style-type: none;
  border: 10px solid yellow;

}

li {
  padding: 5px;
  margin: auto;
  border: 10px  solid red;
}

.logo-container {
  display: flex;
  align-items: center;
  border: 2px solid black;
  margin-left: 2em;

}

.text-box {
  margin-right: 10px;
  margin-left: 20px;
}

.text-box input[type="text"] {
  width: 10px;
}



.navbar-primary-menu {
  display: flex;
  flex-direction: row;  
  justify-content: space-around;
  max-width: 30%;
  border: 2px solid white;

}

.navbar-primary-menu-items {
  border: 2px solid red;
}

.search-container {
  display: flex;
  align-items: flex-end;
  padding: 2px;
  margin-right: 2em;



}

.search-icon {
  border: 2px solid yellow;
 
  max-height: 30px;
  max-width: 30px;
}


.input-field {
  max-height: 100px;
  max-width: 100px;
}

I am attempting to create a navigation bar utilizing flexbox. As a novice in CSS, I'm experimenting to enhance my understanding of styling.

However, I've encountered an issue with the alignment of elements within the navbar. Specifically, there seems to be uneven spacing between the logo container and the menu items.

My goal is to:

  1. Utilize the 'space-between' property
  2. Ensure equal spacing between the middle menu div and both sides of the navbar.

(The discrepancy in the gaps is highlighted by the blue area with stripes in the attached image)

If anyone could provide guidance on how to address this issue, it would be greatly appreciated.

Answer №1

In order to achieve proper alignment with 'space-between' justification, it is necessary to remove the 'nav-content-container' div.

Your 'nav-container' div should ideally contain only 3 divs instead of 4 for optimal spacing and layout.

To gain a better understanding of how justify-content functions, take a look at this resource: https://www.w3schools.com/cssref/css3_pr_justify-content.php

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

Tips for applying a CSS class with a smooth fade-out effect

In my Angular project, I am working on creating a custom notification component. Here is the template code I have so far: <aside *ngFor="let message of messages "> <div class="notification" style="position:fixed"> {{message.conten ...

There is an error in ReactJS: TypeError - _this.props.match is not defined

I am experiencing a TypeError in my console tab and I can't seem to figure out where the error is occurring in my source code. I am relatively new to ReactJS so any help in identifying what I'm doing wrong would be greatly appreciated. Thank you ...

Webkit feature: Rounded border image overlay

One issue arises when applying a rounded border to an image in webkit browsers as the border ends up hidden behind the image. CSS img { border: 10px solid #000; border-radius: 100%; } HTML <img src="http://25.media.tumblr.com/tumblr_mbje ...

Encountering a MUI Error when attempting to import through the Portal

I encountered an issue when trying to import the Portal from mui import {Portal} from @mui/base/Portal; When importing {Portal} from @mui/base/Portal; I'm receiving an error on this line. It seems that mui has released a new version of mui/base Any s ...

Controlling the access to simpleJWT tokens in Django-React authentication to restrict user permissions

My backend has two React frontends: one for general users and the other specifically for admin users with the is_staff attribute. I have customized TokenObtainPairSerializer to add extra fields like 'is_staff'. Now, I'm considering how to r ...

Can the month dropdown in react-datepicker be modified to display numbers instead of names?

Here is the code I have: <DatePicker selected={value?.toDate()} onChange={(date) => this.handleMonthChange(date)} inline showMonthYearPicker dateFormat={this.props.formatString} /> https://i.sstatic.net/SkdGP.png I am seeking ...

What are the steps to ensure Reactstrap is responsive?

I am just starting to explore reactstrap (rather than react-bootstrap) and I'm trying to figure out how to create different layouts for "mobile" and "desktop" views. How can I set up reactstrap to display the page one way in "mobile" view and another ...

Error message: "When using Webpack 4 with Bootstrap, a TypeError occurs where property 'jquery' is read as undefined."

I've recently delved into the world of webpack and everything seems to be running smoothly. However, when I run my webpack app, I encounter the following error within Bootstrap: var version = $.fn.jquery.split(' ')[0].split('.'); ...

React - utilizing dynamic properties using string values

I am facing a challenge in my test suite where I need to generate components with dynamic props. The desired components should look like this: <Button primary /> <Button secondary /> However, I am currently stuck at this point: [ &apos ...

Guide to Applying a Custom Style to Every Icon within the Array (React/Material-ui)

I'm currently working with material-ui icons and I have a scenario where I need to assign a specific icon for each object in an array. Instead of manually applying the "iconStyle" property to each individual icon in the array, I am looking for a more ...

Certain HTML elements on the webpage are not functioning properly when attempting to incorporate a div tag

One of the challenges I'm currently facing is that the links for HOME and ABOUT ME in the header section are not accessible when the 'data' div is added. Strangely, the DOWNLOAD and CONTACT ME links still work fine. This issue seems to be oc ...

Tips on accessing a specific element that has been mapped in React?

TL;DR - I'm struggling to target and open a specific menu from a list generated using map() on an array without a reference. I've encountered an issue with my React.js code that I need assistance with to resolve. The main concept behind this lo ...

The "isActive" value does not share any properties with the type 'Properties<string | number, string & {}>'. This issue was encountered while using React with TypeScript

I'm attempting to include the isActive parameter inside NavLink of react-router-dom version 5, but I'm encountering two errors. The type '({ isActive }: { isActive: any; }) => { color: string; background: string; }' does not have an ...

React App searching for unused static files

Currently, my React application is deployed on the Nginx web server. Accessing the application using the URL XX.XX.XX.XX works fine. However, I want to be able to access it through the URL XX.XX.XX.XX/myapp/frontend. To achieve this, I have set up a revers ...

Is there a way to simulate the change event on a react-select component using react-testing-library?

If I'm unable to directly test the internal components using react-testing-library, how can I effectively test a component that utilizes react-select? For example, if there is a conditional rendering based on the value of the react-select, which does ...

Scrollbar not appearing when overflow-y is set in React Textarea Input on Chrome or Edge

I've been struggling to add a scrollbar to a React Textarea. I've referred to an old post on Stack Overflow here and a few other resources, but haven't had any luck. I've tested it in both Chrome (Version 113.0.5672.129) and Edge (Vers ...

Leverage CSS variables to dynamically create class names within SCSS

Can CSS variables be used to generate class names? I am incorporating SCSS in an Angular project and I am looking to base my class names on the @input color component property. I have stored the input in a CSS variable called --color-variable to utiliz ...

Transitioning between dynamic routes will not refresh the component or page

Got a question about dynamic routing: I have a setup with <Route path=':username' element={ <UserPage /> } />, but when I switch from http://localhost:3000/Fexell to http://localhost:3000/Test, the page doesn't update. Any ideas ...

Utilize Reactjs and Firebase to transform a string into a map structure

I am facing an issue with my reactjs app where I have a "steps" array for users to input recipe preparation steps. Currently, the steps are stored as strings directly in the array on Firebase. However, I want them to be structured within a map. Can someone ...

I am unable to determine the origin or background of my sidebar

I am having an issue with styling a sidebar using HTML and CSS. The problem I am facing is with setting the background-color property. Despite my efforts to customize the style, the background remains transparent and shows the color of the page beneath it. ...