CSS - Panel Expander

No JS Needed

by Adam Kinnucane

HTML

<ul>
	  <div class="expander">
		 <div class="orignal-content">
			<li><a data-filter-value="14mm Chromo">14mm Chromo</a></li>
		 <input id="uniq1" class="expand-control" type="checkbox" />

		 <div class="expand-panel">
		 <li><a data-filter-value="14mm Chromo">14mm Chromo</a></li>
		 </div>
		 <!--the checkbox has to be before the content you wish to show due to the ~ sign but... the label can be after the conent which means the positioning is already correct! which is very powerful-->
		 <label class="expand-label" for="uniq1"></label>
	  </div>
</ul>

CSS

/* Structural CSS */
.expander .expand-panel {
  display: none;
  margin-top: 10px;
  padding: 4px;
}
.expander .expand-header {
  height: 23px;
}

.expander {
  border:1px solid gray;
  padding: 4px;
  padding-bottom: 25px;
}
.expander .expand-control,
.expander .expand-label {
  float: left;
}

/* the expand panel must be a follow sibling or child of checkbox element */
.expander .expand-control:checked ~ .expand-panel {
  display: block;
}

.expander .expand-control:checked#uniq1 {
  display: none;
}

/* styling */

.content {
  width: 300px;
  margin: 0px auto;
}

.expander {
  margin-bottom: 20px;
  position: relative;
}

.expander .expand-label {
  cursor: pointer;
}

.expander .expand-control {
  display: none;
}

.expander input[type='checkbox'].expand-control ~ label:before {
  content: "see more...";
  font-size: 1rem;
  line-height: 20px;
  display: block;
  background-color: #C0C0FF;
  border: 1px solid red;
  text-align: center;
  cursor: pointer;
  margin-left: 5px;
  padding-left: 5px;
  padding-right: 5px;
}

.expander input[type='checkbox'].expand-control:checked ~ label:before {
  content: "see less...";
 
}