Navigation Bar
What We're Aiming For...
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.
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.
The image size needs to be scaled down to fit in the navigation bar. I've picked a size that looks like it fits well.
Add the horizontal links
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.
Solution
Last updated