🪟 Windows TippsAndroid 17: Neue Version ist hier – Das ist alles neu(16.09.2026 um 11:40 Uhr)
🕵️ Hacking12 Best CASB Solutions Compared (2026): Features & Pricing(16.09.2026 um 09:31 Uhr)
🕵️ Hacking12 Best CIEM Tools Compared (2026): Features & Pricing(16.09.2026 um 09:37 Uhr)
🪟 Windows TippsAndroid 17: Neue Version ist hier – Das ist alles neu(16.09.2026 um 11:40 Uhr)
🕵️ Hacking12 Best CASB Solutions Compared (2026): Features & Pricing(16.09.2026 um 09:31 Uhr)
🕵️ Hacking12 Best CIEM Tools Compared (2026): Features & Pricing(16.09.2026 um 09:37 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 3 Min Lesezeit
0

How to Create a Horizontal Navigation Bar Using CSS

↗ Quelle (dev.to)
🗣️ Stimme:

In web design, a horizontal navigation bar is a fundamental element allowing users to navigate different website sections. Creating a sleek and functional navigation bar using structure for our navigation bar. We’ll use an unordered list (<ul>) to hold the list items (<li>) which will represent each navigation link.




CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Horizontal Navigation Bar</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
</html>






Step 2: CSS Styling

Next, let’s style our navigation bar using CSS. We will apply basic styles to the <nav>, <ul>, <li>, and <a> elements to create a horizontal layout.




CODE
/* styles.css */

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

nav {
background-color: #333;
}

nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}

nav ul li {
float: left;
}

nav ul li a {
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;
}

nav ul li a:hover {
background-color: #555;
}






Step 3: Explanation of CSS Styles

body: Resets default margins and ensures no padding.

nav: Sets the background color of the navigation bar.

nav ul: Removes default list styles and ensures no padding or margins.

nav ul li: Floats each list item to the left to create a horizontal layout.

nav ul li a: Displays the anchor tags as block elements with white text centered vertically and horizontally within each list item. Adds padding for spacing and removes underlines.

nav ul li a:hover: Changes the background color of anchor tags on hover to indicate interactivity.

Step 4: Additional Styling and Responsiveness

To make the navigation bar responsive, consider using media queries to adjust styles for different screen sizes. For example:




CODE
@media (max-width: 768px) {
nav ul {
overflow: auto;
}

nav ul li {
float: none;
display: block;
text-align: center;
}

nav ul li a {
padding: 10px;
display: inline-block;
}
}






This code snippet changes the navigation to a vertical layout on screens smaller than 768px wide, making it easier to navigate on mobile devices.



Step 5: Integration and Testing

Finally, integrate your CSS file (styles.css) into your HTML document and test your navigation bar across different devices and screen sizes to ensure it looks and functions as expected.



Creating a horizontal navigation bar using CSS enhances your website’s usability and provides a professional and polished look. With these steps, you can customize your navigation bar to fit the design and style of your website while ensuring it remains accessible and responsive.

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Build Anything with DeepSeek V4.1 Flash, Here's How..
1 Quelle
Followership, CyberSecurity Leadership, and Judgement as a Defining Skill - BSW #465
1 Quelle
Amazon Blitzangebote: MacBook Neo, Powerbanks, EcoFlow + Zendure, Mähroboter und mehr
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Create a Horizontal Navigation Bar Using CSS

Thematisch verwandte Begriffe: Create, Horizontal, Navigation, Using · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...