Struggling to align my Navbar items in one clean line, they seem to pile up and remain fixed on the left side. Utilizing ReactJS and MUi5

I'm struggling with aligning my Navbar items (NavLink) horizontally in one line instead of being stuck on the right side and stacked on top of each other. Can someone help me fix this issue? Here's the code snippet:

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;

Answer №1

You're using display: flex; on the NavigBar component, but not on its div child where all the links are contained.

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

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

State in React Native Firebase is coming back as undefined

Despite trying various approaches, I am still facing the issue of the state being undefined in my code. I've experimented with arrow functions and tried binding 'this' inside the onChange event, but nothing seems to be fixing the problem. Ca ...

Creating a sticky table title and header in Material-Table React: A step-by-step guide

Is there a way to make the table title, search field, global actions icons, and column headers sticky in Material-Table? I attempted using headerStyle in the options but it didn't have any effect (plus it only impacts column headers and not the table ...

Create a Bootstrap multi-bar component for visually displaying the daytime information

I am looking to create a horizontal bar with multiple intervals. Here is what I have tried so far: <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"& ...

The Bootstrap accordion-toggle incorrectly displays the content symbol (+/-) upon initial page load

Hey there, I've implemented the accordion-toggle code below on my visualforce page. Everything is working smoothly with the collapsible toggle, except for one issue. When loading or refreshing the page for the first time, the collapsed panel shows the ...

No matter what I try, connecting the CSS file to my HTML file just won't seem to work

I've been attempting to connect a CSS file to my HTML index file, but I can't seem to get it to work no matter what I try. I'm using VSCode. When typing the link from scratch, it auto-completes or shows up, indicating that it recognizes it. ...

What is the step-by-step process for executing the following functions: 1. magnify -> 2. spin 360 degrees -> 3. restore to original size before magnification -> 4. switch colors on and

Can you show me a demo featuring the following functions in order: 1. enlarge -> 2. rotate 360 degrees -> 3. resize to original size -> 4. change color (toggle) $(document).ready(function() { $('.tlist td div').click(function() { ...

Error message encountered: React hydrate TypeError - the function __webpack_require_.i(...) is not recognized as a

I encountered a webpack TypeError while attempting to use hydrate() in my index.js file. Strangely, the error does not appear when I use ReactDOM.render() instead of hydrate. My intention behind using hydrate was for server-side rendering. src/index.js i ...

The function within setInterval is not functioning as expected within ReactJs

I have come across numerous tutorials on implementing timers in React using a code snippet like this useEffect(() => { let interval = null; if (timeractive) { interval = setInterval(() => { setCount(count => coun ...

Utilizing border-radius specifically on the ul element to apply rounded corners to only the outer li items

I'm exploring a concept where I want to create a curved border around the list items, both on the outside and inside. Here are some examples: Right Check out the correct curved border here Wrong: See the incorrect curved border here Please note, ...

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The server is unable to process the request sent by the browser or proxy. This error occurred in a Flask web application

Can someone guide me on troubleshooting this issue in Flask? I am still learning. Server running at (Press CTRL+C to exit) 127.0.0.1 - - [26/Jul/2020 11:19:45] "GET /predict HTTP/1.1" 500 - Traceback (most recent call last): raise exceptions. ...

How can you store previously calculated values in a costly recursive function in a React application?

Consider a scenario where there is a recursive callback function like the one shown below: const weightedFactorial = useCallback(n => { if (n === 0) { return 1; } return weight * n * weightedFactorial(n - 1); }, [weight]); Is it possible to ...

What is the best way to showcase HTML content in columns with a horizontal scrolling feature?

I am trying to showcase a list of basic HTML elements such as divs, paragraphs, etc. within a fixed height container, arranged in columns with consistent width. I want them to be horizontally scrollable, similar to the layout displayed in this image. Thi ...

Adjust the element colors within a Vue loop with dynamic changes

Hey there! I'm currently working on achieving a unique design inspiration that involves colorful badges grouped together. Here's a visual reference: https://i.sstatic.net/5LDBh.png In the image, you can see these badges grouped in pairs, but the ...

Can delayed validation be implemented for a control in react-form-hook?

One challenge I am facing is implementing a custom validation for an Input field with the mode set to "onChange". The custom validation involves checking if the user input text is present in an array of strings. However, there is concern that as the array ...

Guide to containing multiple grid containers within a React Fragment component

Organization- Consider a footer component that outputs the following JSX, and then I am utilizing the footer component within a LoginPage component. <React.Fragment> [container1...(full width)] [container2...(width- 60%)] [container3...(width- 40%)] ...

Upon modifying the selection, I am notified to utilize the 'defaultValue' or 'value' props on the <select> tag, rather than applying 'selected' on the <option> tag

I am currently working with a material select component: <FormControl fullWidth variant="outlined" className={classes.formControl}> <InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple"> Filial </InputLabel> <Sel ...

Remove the boundaries from the grid and only retain the box

I am not skilled in css, but I simply want to eliminate the interior edges of the box and retain only the outer edges. .grid-container { display: grid; grid-template-columns: auto auto auto; background-color: #2196F3; padding: 10px; } .grid-ite ...

What is the best way to include a disable option or default option in a select box?

I am incorporating react material in react using the select component. My goal is to include a first disabled option that says "please select item." This is how it's currently implemented in HTML: <select name="tagging"> <option sel ...

The event listener for onChange on my dropdown menu is not functioning as expected

Hey, I'm trying to achieve something when my select box changes. Here's my code snippet: function Task(){ const prints = (e) =>{ console.log("it prints"); } const prints2 = (e) =>{ console.log("it ...

Modify the CSS property of a checkbox label when the checkbox is selected

Recently, I came across some interesting HTML code: <label> <input type="checkbox" value="cb_val" name="cb_name"> my checkbox text </label> After applying CSS, I successfully added a background-color to the <label> t ...