What is the best way to shift a list to the right within my navigation bar using ReactJS and CSS?

I'm looking to align a list to the right in my navbar, as shown in the image below

Image

Here's my navbar.js code:

import React from "react";
import "./Navbar.css";

const Navbar = ({ isScrolling, information }) => {
    const toTheTop = () => {
        window.scrollTo({ top: 0, left: 0, behavior: "smooth" });
    };

    return (
        <nav className={`navbar ${isScrolling > 20 ? "scrolling" : null}`}>
            <div
                className={`navbar-logo ${
                    isScrolling > 20 ? "scrolling-logo" : null
                }`}
                onClick={toTheTop}
            >
                <p>{information.name}</p>
            </div>

            <div
                className={`navbar-links box ${
                    isScrolling > 20 ? "scrolling-links" : null
                }`}
            >
                <ul>
                    {information.directions.map((direction) => (
                        <li key={direction.key}>
                            <a href={direction.url}>{direction.name}</a>
                        </li>
                    ))}
                </ul>
            </div>
        </nav>
    );
};

export default Navbar;

And here's my Navbar.css styling:

.navbar {
    display: flex;
    position: fixed;
    top: 0;
    background-color: transparent;
    width: 100%;
    height: 80px;
    font-size: 20px;
    z-index: 1;
}

.scrolling {
    background-color: #000;
    transition: all 0.5s ease;
}

.navbar-logo {
    display: flex;
    align-items: center;
    padding-left: 50px;
    color: #000;
    cursor: pointer;
}

/* additional styles for list alignment */
.navbar-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.navbar-links > ul {
    display: flex;
    flex-direction: row;
    list-style: none;
}

.navbar-links > ul > li {
    padding: 0 5%;
}

.navbar-links > ul > li > a {
    color: #000;
}

/* additional styling for scrolling */
.scrolling-links > ul > li > a {
    color: #fff;
    transition: all 0.5s ease;
}

Feel free to check out the code for my project on my GitHub repository https://github.com/Michael-Liendo/michaelliendo.com

Answer №1

To achieve this, you can utilize the justify-content: space-between; property. However, keep in mind that it may not function correctly at the moment.
This is likely due to the fact that you have applied position: fixed; without specifying values for left or right.
To address this issue, you can employ the following CSS code:

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: transparent;
    width: 100%;
    height: 80px;
    font-size: 20px;
    z-index: 1;
}

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

Struggling with executing a React command

After upgrading my npm and cleaning up some unnecessary packages, I'm still encountering some strange issues when attempting to run a particular command: kalebamarante$ npm init create-react-app kalebcryptoexchange-app npm ERR! code E404 npm ERR! 404 ...

"Exploring the insertion of a line break within the modal body of an Angular application

Is it possible to create a modal for error messages with multilined body messages without altering the modal template? Any assistance would be greatly appreciated. <div class="modal-body" > <p *ngIf="!_isTranslatable">{{_modalBody}}</p&g ...

Implementing Oauth in Angular and Node

I am facing challenges with implementing oauth in Angular. When I directly enter the link into the browser http://localhost:8080/auth/twitter I am able to successfully connect using oauth and receive a response. However, when I try to achieve the same in ...

$scope.apply is triggering both "catch" and "then" handlers

I am trying to ensure that the content of a page in Angular 1.6.2 and UI router is only displayed once it has been confirmed on the server that the user has the appropriate role/permissions. It seems like without using $scope.apply(), the catch() function ...

A custom-designed Material UI TextField featuring a specific date and time picker capable of displaying seconds

Currently, I am facing an issue while using react-admin and trying to modify the date and time, specifically including seconds with the help of DateTimeInput. Unfortunately, my attempts have been unsuccessful so far. Here is what I have tried: Approach 1: ...

What is the process for defining states in hooks?

I am currently trying to refactor my code from a class-based component to a functional component. The challenge lies in updating states and methods, specifically within the setState function. Here is a snippet of my current code: const [userForm, setUserFo ...

React is struggling to locate the specified module

Once I've set up my react project using npx create-react-app called my-app, I proceed to run npm start only to encounter the error shown in the image below. Running node version: 12.16.1 with npm version: 6.13.4 View the error message her ...

Having trouble adjusting the height of <a> elements in the navbar

My navbar has an issue where the listed items do not fill the entire height of the navbar. I have tried adjusting padding and margin, but it doesn't seem to be affecting the layout. Any suggestions would be greatly appreciated. Thank you. #navbar { ...

Using querySelector to Target Elements by their InnerHTML Content

Is it possible to target an element by its innerHTML directly without the use of loops? Is there a way to achieve this with something like document.querySelector('div[innerHTML="Sometext"]') or document.querySelector('div[textcontent="Som ...

What exactly is the functionality of the jQuery.on() method?

I am curious about the functionality of this function and how it operates. Does it follow these steps: Identify element(s) using their selectors Assign event-handlers to them Execute a setInterval on that selector, consistently delegating and then undeleg ...

Javascript encountered an error upon attempting to return from the main function

I have a function that calls the database to perform an action: function callQuery(query) { db.query(query, (err, res) => { if (err) { // Error connecting to DB console.log(err.stack) } else { // Return the results ret ...

Triggering the Select component in React Material UI manually

Looking to replicate the functionality of Material UI's language changer? Check out https://material-ui.com/. I've combined an icon and Mui Select into a Mui Button for this purpose. If you have any suggestions for a more efficient approach, fee ...

Ways to configure dynamic and responsive divs using CSS exclusively (no javascript needed)!

I am looking to have my main div expand in height based on the categories div, content, or product pictures. Check out the website here Here are the issues I'm facing: The content div and categories div are both within the main div, but the produ ...

Replacing CSS conditional statements with jQuery

My CSS code is set to hide the #global-widget-base tag and display a tab #aside-expander when the browser width is less than 1200px. @media screen and (max-width: 1200px) { aside#global-widget-base { display: none !important; } #aside- ...

The transitionend event fails to trigger if there is no active transition taking place

Take a look at this: http://jsfiddle.net/jqs4yy0p/ JS $('div').addClass('switch').on('transitionend', function(e){ alert('end'); }); CSS div { background-color: red; /*transition: background-colo ...

Is it possible to place a div element from an aspx page into the div of an html page?

Currently, I am faced with the challenge of loading a specific DIV from an ASPX page into an HTML page. The ASPX page tends to load slowly, while the HTML page loads much faster. Therefore, I am attempting to display the DIV that takes time to load from t ...

Can we use a switch statement instead of having multiple @Input()s in Angular?

When passing an attribute into my Angular component like this: <my-component myAttribute></my-component> I aim to modify a variable within the component that controls the CSS properties for width and height. To simplify, I have predefined at ...

Tips for incorporating a spinner during content loading within AngularJS

When the user clicks on the "Search" button, content will load and the button label will change to "Searching" with a spinner shown while the content is loading. Once the content has loaded (Promise resolved), the button label will revert back to "Search" ...

The wrapper.find function is malfunctioning as a result of a connection issue

There seems to be an issue with the following test case using jest and enzyme: it('Displays Trade component', () => { console.log("Testing Shallow", wrapper) expect(wrapper.find('Trade').length).toEqual(1); }); To debug, ...

Various relationships in Sails.js

Exploring associations in Sails.js beta (version 0.10.0-rc4) has been quite intriguing for me. My current challenge involves linking multiple databases to produce a unified result (utilizing sails-mysql). The association scheme I'm working with invo ...