Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't get to make my Navbar items be in one line, they're stacked up and stuck on the left. ReactJS MUi5

I have a logo on my left. I want to have my Navbar items (NavLink) to be horizontally spaced out and in one line, currently they’re stuck on the right side and on top of each other.
Here’s the code:

import React from "react";
import { Toolbar, Typography } from "@mui/material";
import { styled } from '@mui/material/styles'
import { NavLink } from "react-router-dom";
import Logo from '../assets/travelLogo.png'

const NavigBar = styled(Toolbar)(({theme}) =>({
  backgroundColor: theme.palette.background.default,
  display: 'flex',
  justifyContent: 'space-between',
  textAlign: 'center',
}));
const NavigTypo = styled(Typography)(({theme}) => ({
    display: 'flex',
    justifyContent: 'space-between',
    color: "white",
}));
function Navbar(){
    return(
        <NavigBar>
            <img src={Logo} alt="logo"/>
            <div>
              <NavLink to="/">
                  <NavigTypo variant="h5" >
                      HOME
                  </NavigTypo>
              </NavLink>
              <NavLink to="/info">
                  <NavigTypo variant="h5" >
                      INFO
                  </NavigTypo>
              </NavLink>
              <NavLink to="/contact">
                  <NavigTypo variant="h5" >
                      CONTACT US
                  </NavigTypo>
              </NavLink>
            </div>
        </NavigBar>
    )
}

export default Navbar;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are styling with display: flex; NavigBar and not its div child which contains all the links.

const NavigBar = styled(Toolbar)(({theme}) =>({
  backgroundColor: theme.palette.background.default,
  display: 'flex',
  justifyContent: 'space-between',
  textAlign: 'center',
  '& div': {
    display: flex;
  }
}));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading