We want to create a navigation bar with a logo on the left and the nav elements distributed evenly along the horizontal line.
Add the nav container
First, we use the <nav> semantic element to wrap the navigation bar. And we'll add a class so that we can target it for styling.
<nav class="nav-container">
</nav>
Add the navbar logo
Next, we'll add the img element for the logo. I've wrapped it in an anchor. This is how you create a link with an image instead of text. So when the user clicks on the logo, it would take them to the home page.
Unordered list elements (<ul>, <li>) are used to implement navigation bars because they are ideally suited to the task since they are designed to represent a hierarchical structure of any depth. This navigation bar is only one level, but that's not always the case (take a look at the navigation bar on the cnbc.com site)
There are two CSS properties on the list element (ul or ol) that must be changed from the defaults to make a list into a navigation bar.
list-style: none This removes to bullet icon for each list item
display: flex In this situation we are using it to cause the list items to flow from left to right across the available space.
Adding a :hover selector for mouse-over events on the navigation bar
We used this in the last exercise to hover over the "Learn More" button on the showcase article. We're going to apply the same technique here on the navigation item links. The link color will change as long as the user's mouse remains hovered over the list item.
.nav-container {background:#fff;padding:18px;display:flex;width:100%;}/* this style centers the image within the anchor */.nav-container>a {display:flex;justify-content:center;align-items:center;}.nav-container.logo {width:180px;}/* default style for mobile width */.nav-containerul {display:flex;flex-direction:column;list-style:none;}/* style for larger widths */@mediascreenand (min-width:600px) {.nav-containerul {flex-direction:row;width:100%;justify-content:space-around; }}.nav-containerli {font-weight:bold;}.nav-containera:hover {color:var(--primary-color);}