Dieser Artikel erklärt, wie man mit CSS eine Navigationsleiste mit Suche erstellt.

Die folgenden Beispiele sind alle responsiv.

Sie können sich zunächst das Vorschaubild ansehen:

Suchleiste erstellen

HTML-Code

<div class="topnav"> <a class="active" href="#home">Startseite</a> <a href="#about">Über uns</a> <a href="#contact">Kontakt</a> <input type="text" placeholder="Suchen.."> </div>

CSS-Code

/*Fügen Sie der oberen Navigationsleiste eine schwarze Hintergrundfarbe hinzu*/ .topnav { overflow: hidden; background-color: #e9e9e9; } /*Stil der Links in der Navigationsleiste festlegen*/ .topnav a { float: left; display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } /*Linkfarbe beim Hover ändern*/ .topnav a:hover { background-color: #ddd; color: black; } /*Aktuell ausgewähltes Element hervorheben*/ .topnav a.active { background-color: #2196F3; color: white; } /*Stil des Suchfelds in der Navigationsleiste festlegen*/ .topnav input[type=text] { float: right; padding: 6px; border: none; margin-top: 8px; margin-right: 16px; font-size: 17px; } /*Wenn die Bildschirmbreite kleiner als 600px ist, Menüoptionen und Suchfeld vertikal gestapelt anzeigen*/ @media screen and (max-width: 600px) { .topnav a, .topnav input[type=text] { float: none; display: block; text-align: left; width: 100%; margin: 0; padding: 14px; } .topnav input[type=text] { border: 1px solid #ccc; } }

Selbst ausprobieren »

Weitere Beispiele

Beispiel - Suchnavigationsleiste mit Absenden-Schaltfläche


Selbst ausprobieren »

Beispiel - Suchnavigationsleiste mit Suchsymbol


Selbst ausprobieren »