Vertical Accordion Nav Menu (CSS Only)

by Jordan Dayton

HTML

<div class="nav">
  <input type="checkbox" id="menu" checked />
  <label for="menu"></label>

  <div class="multi-level">
    <div class="item">
      <input type="checkbox" id="A" />
      <label for="A">Category One</label>
      <ul>
        <li><a href="#">Sub-Category One</a></li>
        <li><a href="#">Sub-Category Two</a></li>
        <li><a href="#">Sub-Category Three</a></li>
      </ul>
    </div>
    <div class="item">
      <input type="checkbox" id="B" />
      <label for="B">Category Two</label>
      <ul>
        <li><a href="#">Sub-Category One</a></li>
        <li>
          <div class="sub-item">
            <input type="checkbox" id="B-A" />
            <label for="B-A">Sub-Category Two</label>
            <ul>
              <li><a href="#">Sub-Sub-Category-1</a></li>
              <li><a href="#">Sub-Sub-Category-2</a></li>
              <li><a href="#">Sub-Sub-Category-3</a></li>
              <li><a href="#">Sub-Sub-Category-4</a></li>
              <li><a href="#">Sub-Sub-Category-5</a></li>
              <li><a href="#">Sub-Sub-Category-6</a></li>
            </ul>
          </div>
        </li>
      </ul>
    </div>
    <div class="item">
      <input type="checkbox" id="C" />
      <label for="C">Category Three</label>
      <ul>
        <li><a href="#">Sub-Category One</a></li>
        <li><a href="#">Sub-Category Two</a></li>
        <li><a href="#">Sub-Category Three</a></li>
      </ul>
    </div>
    <div class="item">
      <input type="checkbox" id="D" />
      <label for="D">Category Four</label>
      <ul>
        <li><a href="#">Sub-Category One</a></li>
        <li><a href="#">Sub-Category Two</a></li>
        <li><a href="#">Sub-Category Three</a></li>
      </ul>
    </div>

  </div>

</div>

CSS

/*Global*/

html,
body {
  width: 100%;
  margin: 0;
  padding: 0;
  font-family: helvetica;
}

/*Functionalty*/

.multi-level,
.item ul,
.nav input[type="checkbox"] {
  display: none;
}

#menu:checked~.multi-level,
.item input:checked~ul {
  display: block;
}

/*Arrow*/

.arrow {
  width: 10px;
  height: 10px;
  vertical-align: middle;
  float: left;
  margin: 9px 0.5em 0 2em;
}

.item input+.arrow {
  transform: rotate(-90deg);
  transition: 0.1s;
}

.item input:checked+.arrow {
  transform: rotate(0deg);
  transition: 0.1s;
}

img {
  z-index: 1;
  position: relative;
}

/*Styles*/

label:hover {
  cursor: pointer;
  background-color: #f2f2f2;
  position: relative;
}

li:hover {
  background-color: #f2f2f2;
}

label {
  width: 100%;
  display: block;
  position: relative
}

.nav {
  width: 100%;
  background-color: white;
  overflow-x: hidden;
  /*border-bottom: 1px solid #CFD8DC;*/
}

/*#nav-icon {
    font-size: 28px;
    line-height: 50px;
    padding-left: 1em;
    color: white;
    background-color: #F44336;
}*/

.nav ul,
.nav li,
label {
  line-height: 30px;
  margin: 0;
  padding: 0 2em;
  list-style: none;
  text-decoration: none;
  color: #000;
  font-weight: 100;
  width: 100%;
}

.item ul {
  margin-left: -3em;
}

.nav li a {
  line-height: 30px;
  margin: 0;
  padding: 0 2em;
  list-style: none;
  text-decoration: none;
  color: #000;
  font-weight: 100;
}

.item label:before {
  content: '';
  background: url(https://png.icons8.com/material/50/000000/expand-arrow.png);
  width: 10px;
  background-size: 100%;
  height: 10px;
  position: absolute;
  top: 9px;
  left: 13px;
  transform: rotate(-90deg);
}

.item input:checked+label:before {
  transform: rotate(0);
}

.sub-item {
  padding: 0 0m;
}