NAVIGATION BAR IN HTML AND CSS


code for creating a navigation bar in HTML and CSS:

HTML Code:

<nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Services</a></li> <li><a href="#">Portfolio</a></li> <li><a href="#">Contact Us</a></li> </ul> </nav>

Explanation:

The navigation bar is created using the HTML <nav> element, which indicates that the enclosed content is a navigation section. Within the <nav> element, we have a <ul> element, which represents an unordered list of items.

Each list item is represented by an <li> element. Within each list item, we have an anchor tag <a> that provides the link to the respective page. The href attribute within the <a> tag specifies the URL to which the link should navigate. In this example, the link is set to "#" to indicate that it's a placeholder link, and does not navigate to any specific page.

CSS Code:

    nav {          background-color: #333;         overflow: hidden;     }     nav ul {         margin: 0;         padding: 0;         list-style: none;     }     nav li {          float: left;     }     nav li a {         display: block;         color: white;         text-align: center;          padding: 14px 16px;          text-decoration: none;     }     nav li a:hover {          background-color: #111;     }

Explanation:

The CSS code is used to style the navigation bar. The nav selector is used to select the navigation bar, and the background-color property is set to #333 to set the background color of the navigation bar.

The overflow: hidden; property is used to prevent any content inside the navigation bar from overflowing outside the bar.

The ul selector is used to select the unordered list, and the margin, padding, and list-style properties are set to 0 to remove any default spacing and list-style.

The li selector is used to select each list item, and the float: left; property is set to align the items horizontally.

The a selector is used to style the anchor tags within the list items. The display: block; property is used to make the anchor tags take up the entire width of the list items. The color, text-align, and padding properties are used to style the text within the anchor tags.

The text-decoration property is set to none to remove the underline from the anchor tags.

Finally, the a:hover selector is used to apply the background color of #111 when the user hovers over the anchor tags.

By using this code, you can create a navigation bar in HTML and style it using CSS.