Wie erstelle ich: Suchleiste
Lernen Sie, wie Sie ein Suchfeld in einer responsiven Navigationsleiste hinzufügen.
Suchleiste
Suchleiste erstellen
Erster Schritt - HTML hinzufügen:
<div class="topnav"> <a class="active" href="#home">Zuhause</a> <a href="#about">Über</a> <a href="#contact">Kontakt</a> <input type="text" placeholder="Suchen.."> </div>
Schritt 2 - CSS hinzufügen:
/* Schwarzen Hintergrund für die obere Navigationsleiste hinzufügen */ .topnav { overflow: hidden; background-color: #e9e9e9; } /* Stil für die Links in der Navigationsleiste einstellen */ .topnav a { float: left; display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } /* Ändern Sie die Farbe des Links bei der Überlegung */ .topnav a:hover { background-color: #ddd; color: black; } /* Stil für das "aktive" Element einstellen, um die aktuelle Seite hervorzuheben */ .topnav a.active { background-color: #2196F3; color: white; } /* Stil für das Suchfeld in der Navigationsleiste einstellen */ .topnav input[type=text] { float: right; padding: 6px; border: none; margin-top: 8px; margin-right: 16px; font-size: 17px; } /* Wenn die Bildschirmbreite weniger als 600px beträgt, werden die Links und das Suchfeld vertikal gestapelt anstatt horizontal angeordnet */ @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; } }
Beispiel mit Einreichungs-Schaltfläche
Beispiel mit Einreichungs-Symbol
相关页面
教程:如何创建响应式顶部导航
教程:CSS 导航栏