Creating a Smooth Sliding Menu

This is a companion discussion topic for the original entry at http://www.kirupa.com/html5/creating_a_smooth_sliding_menu.htm

After 5 years, this tutorial got a well deserved make over. Mostly minor changes here and there! :stuck_out_tongue:

Look, ma, no JavaScript!

<style>
menu {
  position: fixed;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: -100vw;
  margin: 0;
  background: black;
  transition: left 500ms;
  list-style: none;
}
menu a {
  font-size: 2rem;
  text-decoration: none;
  color: white;
}
button:focus + menu {
  left: 0vw;
}
</style>
<button>Menu</button>
<menu>
  <li><a href="#">Home</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Contact</a></li>
  <li><a href="#">Search</a></li>
</menu>

JSFiddle demo

1 Like