Home > Blockchain >  How do I move a list to the right in my navbar? in reactjs and css
How do I move a list to the right in my navbar? in reactjs and css

Time:11-18

I want to move in my navbar a list to the right, as the image below indicates

Image

My navbar.js: the class is navbar-links

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;

my Navbar.css: I already tried using display: flex; align-items: center; justify-content: flex-end; But it does not work

.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;
}

.scrolling-logo {
    color: #fff;
    transition: all 0.5s ease;
}
/* here is the div of my list */
.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% 0 5%;
}

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

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

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

for view my code of the my proyect visit my repository https://github.com/Michael-Liendo/michaelliendo.com

CodePudding user response:

You can do it by justify-content: space-between;, but it doesn't work properly now.
Because you set position: fixed; and not set left or right.
So you can do it by this 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;
}
  • Related