14
Step 7: Style the Nav Bar (10 mins)
Navigation bars or nav bars are an essential part of a website, allowing the user to move back and forth
to different pages on a website. There are some standard designs and structures used for nav bars,
including vertical and horizontal layouts. We will walk you through styling your navigation bar
horizontally, but if you want to explore more ways to style your navigation bar we recommend checking
out this resource from W3Schools or this resource from MDN.
Style the <ul> Element
To style our navigation bar, we will focus on applying styles to
the <ul>, <li>, and <a> elements. First, let’s remove the
bullets from the unordered list, or <ul> element, most nav
bars don’t have bullets. In order to do this you will set the
property list-style-type to none for the ul element. You can
also give your nav bar a background color by setting the
background-color property for the ul element. The overflow
property helps give our ul property height so it is displayed
properly. (We need to use it if we use the float property, which
we use below.)
Style the <li> Elements
Next let’s make the elements in our list, or the <li> elements
display in a horizontal line rather than stacked on top of each
other. We can do this by adding a rule set and setting the
display property to inline. Unlike the block value we
used for the img tag, inline allows multiple elements to be on
one line. We also want them positioned on the right side of
the page, so we will use the float property and set it to right.
You should see something similar to this:
Add these properties to the ul rule set
under the /* CSS FOR NAV BAR */
comment. Change the color value
based on your mockup.
ul {
list-style-type: none;
background-color: #43d6b9ff;
overflow: hidden;
}
Add these properties to the li rule set
under the /* CSS FOR NAV BAR */
comment.
li {
display: inline;
float: right;
}
Remember that a navigation bar is just a list of links. Right
now, your HTML for your navigation bar should look similar to
the HTML on the right.