Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active January 25, 2021 10:24
Show Gist options
  • Save acidtone/54743952224fcc62435604e7d92e3795 to your computer and use it in GitHub Desktop.
Save acidtone/54743952224fcc62435604e7d92e3795 to your computer and use it in GitHub Desktop.
Navigation list: reset browser defaults

Navigation: Resetting default list styles

Lists come with a few browser defaults that usually need to be reset before they can be used for navigation.

  1. Remove list bullets:

    nav li {
      list-style: none;
    }
  2. Remove list padding (usually 40px):

    nav ul {
      padding: 0;  
    }
  3. This is a tricky one. Links are inline by default. We need to set them to block so that proper padding and width can be applied.

    nav a {
      display: block;
    }

Assumptions

Standard html navigation menu:

<nav>
  <ul class="container">
    <li><a href="#">Fighter</a></li>
    <li><a href="#">Wizard</a></li>
    <li><a href="#">Bard</a></li>
    <li><a href="#">Rogue</a></li>
  </ul>
</nav>

Background material

  1. HTML
  2. CSS Selectors:
  3. Box model:

Related Gists

From here, the list can be further styled to create a navigation menu:

<nav>
<ul>
<li><a href="#">Fighter</a></li>
<li><a href="#">Wizard</a></li>
<li><a href="#">Bard</a></li>
<li><a href="#">Rogue</a></li>
</ul>
</nav>
nav ul {
padding: 0;
}
nav li {
list-style: none;
}
nav a {
display: block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment