如何居中一个简单的导航栏?

How to center a simple navbar?

几个小时以来,我一直在努力让导航栏居中。

这里是:

[[1]: https://i.stack.imgur.com/Wi2RD.png][1]

如您所见,导航元素稍微偏左,而不是 body 居中。 (body 完全居中)。

这是我的代码:

 header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(0deg, rgba(164, 174, 228, 0.05), rgba(164, 174, 228, 0.05)), #080B1C;
}

.logohome {
    position: relative;
    width: 350px;
    display: flex;
}

.nav__links a,
.overlay__content a {
    font-family: "Montserrat", sans-serif;
    font-weight: 500;
    color: #edf0f1;
    text-decoration: none;
}

.nav__links {
    list-style: none;
    display: flex;
}

.nav__links li {
    margin-right: 18rem;
}

.nav__links li a {
    transition: color 0.3s ease 0s;
}

.nav__links li a:hover {
    color: #A4AEE4;
}

.NP {
    position: absolute;
    margin-right: 4.6rem;
    right: 0;
    color: #24252a;
    font-family: "Montserrat";
    font-weight: 700;
    font-style: normal;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.profile {
    border-radius: 50%;
    margin-right: 4rem;
    width: 50px;
    transition: background-color 0.3s ease 0s;
    z-index: 0;
}

.dropbtn {
    position: absolute;
    margin-left: 4.5rem;
    bottom: 2px;
    width: 25px;
    background-color: transparent;
    color: white;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

和 html :

<header>
        <img href="google.com" class="logohome" src="images/logo.png"><br><br>

        <nav>
            <ul class="nav__links">

                <li><a href="/favoris.html">Mes Favoris </a></li>
                <li><a href="#">Accueil</a></li>
                <li><a href="/stats.html">Mes Statistiques</a></li>

                <img src="/images/navstate.png" class="navstate">

            </ul>
        </nav>
        <a class="cta" href="#"></a>

        <img src="/images/iconeprofile.png" class="profile">
        <div class="NP">NP
            <div class="dropdown">
            </div>
            <img src="/images/drop.png" onclick="myFunction()" class="dropbtn">
            <div id="myDropdown" class="dropdown-content">
                <a href="#">Mon profil</a>
                <a href="#">Nous contacter</a>
                <a href="#">Déconnexion</a>
            </div>
        </div>
      </header>

我应该更改或实施哪些参数才能使其工作得很好? (我不想做超级响应吧,只是干净,目的是一个web app)

这将解决它。除了最后一个元素之外的所有元素都将具有 margin-right。如果需要,也不要忘记重置 ul 边距和填充。

.nav__links {
    list-style: none;
    display: flex;
    margin: 0;
    padding: 0;
}
.nav__links li:not(:last-child) {
    margin-right: 18rem;
}