JSFiddle - React, Tailwind, and code Playground

CSS-Only Show More Toggle

by skibulk

HTML

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<p>Hello World<p>
<div class="show-hide-wrapper">
	<input id="cb1" class="show-hide-checkbox" type="checkbox">
	<div class="show-hide-content-wrapper">
		<div class="show-hide-content">
			<p>Hello World</p>
		</div>
	</div>
	<label for="cb1" class="show-hide-label">
		<span class="show-hide-more">Show More</span>
		<span class="show-hide-less">Show Less</span>
	</label>
</div>

CSS

.show-hide-wrapper {
	position: relative;
}

.show-hide-checkbox {
	position: absolute;
	clip: rect(1px, 1px, 1px, 1px);
}

.show-hide-checkbox:not(:checked) ~ .show-hide-label .show-hide-less {
	display: none;
}

.show-hide-checkbox:checked ~ .show-hide-label .show-hide-more {
	display: none;
}

/*
.show-hide-content-wrapper {
	max-height: 0;
	overflow-y: hidden;
	-webkit-transition: max-height 1s;
	-moz-transition: max-height 1s;
	-o-transition: max-height 1s;
	transition: max-height 1s;
}

.show-hide-checkbox:checked ~ .show-hide-content-wrapper {
	max-height: 800px;
}
*/

.show-hide-checkbox:not(:checked) ~ .show-hide-content-wrapper {
	display: none;
}

.show-hide-label {
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
	
	border: 1px solid gray;
	padding: 10px;
}