Show More/Less Pure CSS

by Rupesh Kokal

HTML

<h3>Pure CSS "Show More/Less" functionality without Transitions<br>(slideToggle effect with no JavaScript).</h3>

<ul>
  <li><a href="#">One</a></li>
  <li><a href="#">Two</a></li>
  <li><a href="#">Three</a></li>
  <li><a href="#">Four</a></li>
  <li class="container">
    <input type="checkbox" id="check_id">
    <label for="check_id"></label>
    <ul>
      <li><a href="#">Five</a></li>
      <li><a href="#">Six</a></li>
      <li><a href="#">Seven</a></li>
      <li><a href="#">Eight</a></li>
      <li><a href="#">Nine</a></li>
      <li><a href="#">Ten</a></li>
    </ul>
  </li>
</ul>

CSS

/* RESET-BASIC STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  background: #e9ecef;
}

h3 {
  background: #1C1D1F;
  color: white;
  width: 80%;
  text-align: center;
  margin: 15px auto;
  padding: 10px;
}

ul {
  width: 50%;
  margin-left: auto;
  margin-right: auto;
  list-style-type: none;
  background: white;
}

li {
  height: 50px;
  line-height: 50px;
  border-top: 1px solid #e9ecef;
}

ul a {
  display: block;
  height: 100%;
  text-decoration: none;
  color: black;
  padding-left: 10px;
  position: relative;
  -webkit-transition: background .3s;
          transition: background .3s;
}

ul a:after {
  content: '⇢';
  position: absolute;
  right: 10px;
}

ul a:hover {
  background: #cdcbc4; 
}



/* CHECKBOX CONTAINER STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */

.container { 
  position: relative; 
  height: auto;
  border-top: 0;
}

[type="checkbox"] {
  position: absolute;
  left:  -9999px;   
}

label {
  background: #e4e3df;
  display: block;
  width: 100%;
  height: 50px;
  cursor: pointer;
  position: relative;
  /*
   * no need to position absolutely the element 
   * because we are not interested in any transition effect
   * position: absolute;
   * top: 0;
   */
}

/*
 * use the rule below for testing purposes
 * label:hover {
 *    background: yellow;
 *  }
 */

label:before,
label:after {
    position: absolute;
}

label:before {
  content: 'More';
  left: 10px;
}

label:after {
  content: '⇣●';
  right: 10px;
  -webkit-animation: sudo .85s linear infinite alternate;
          animation: sudo .85s linear infinite alternate;
}

@keyframes sudo { 
    from { 
    -webkit-transform: translateY(-2px); 
            transform: translateY(-2px); 
  }
    to { 
    -webkit-transform: translateY(2px); 
            transform: translateY(2px); 
  }
}

input[type="checkbox"] ~ ul {
  width: 100%;
    display: none;
}



/* CHECKED STATE...