Wie man eine zentrierte obere Navigationsleiste erstellt

Lernen Sie, wie Sie eine Navigationsleiste mit zentriertem Link/Symbol erstellen.

Versuchen Sie es selbst

Erstellen Sie eine obere Navigationsleiste

Schritt 1 - Fügen Sie HTML hinzu:

<!-- Ober navigationsleiste -->
<div class="topnav">
  <!-- Zentrenverweis -->
  <div class="topnav-centered">
    <a href="#home" class="active">Home</a>
  </div>
  /* Links ausrichten links (standardmäßig) */
  <a href="#news">Nachrichten</a>
  <a href="#contact">Kontakt</a>
  /* Links ausrichten rechts (standardmäßig) */
  <div class="topnav-right">
    <a href="#search">Suche</a>
    <a href="#about">Über uns</a>
  </div>
</div>

Zweiter Schritt - CSS hinzufügen:

/* Schwarzen Hintergrund für die obere Navigationsleiste hinzufügen */
.topnav {
  position: relative;
  background-color: #333;
  overflow: hidden;
}
/* Stile für Links in der Navigationsleiste festlegen */
.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}
/* Ändern Sie die Farbe der Links bei der Mausüberlegung */
.topnav a:hover {
  background-color: #ddd;
  color: black;
}
/* Farbe für aktive/aktuelle Links hinzufügen */
.topnav a.active {
  background-color: #04AA6D;
  color: white;
}
/* Zentrierte Komponente im oberen Navigationsbereich */
.topnav-centered a {
  float: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
/* Rechte Ausrichtung im oberen Navigationsbereich */
.topnav-right {
  float: right;
}
/* Responsives Navigationsmenü - Links werden auf mobilen Geräten gestapelt angezeigt, anstatt nebeneinander */
@media screen and (max-width: 600px) {
  .topnav a, .topnav-right {
    float: none;
    display: block;
  }
  .topnav-centered a {
    position: relative;
    top: 0;
    left: 0;
    transform: none;
  }
}

Versuchen Sie es selbst

Related pages

Tutorial:How to create a responsive top navigation

Tutorial:CSS navigation bar