Last active
June 5, 2016 07:16
-
-
Save chrisdlangton/b6662941b44dc750a5160e2b43db0b78 to your computer and use it in GitHub Desktop.
Visibility Toggle using pure CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.toggle { | |
margin: 0 auto; | |
max-width: 400px; | |
} | |
.toggle-label { | |
font-size: 16px; | |
background: #fff; | |
padding: 1em; | |
cursor: pointer; | |
display: block; | |
margin: 0 auto 1em; | |
box-shadow: 0 1px 2px 0 rgba(153, 153, 153, 0.35); | |
border-radius: 4px; | |
&:after { | |
color: #ED3E44; | |
content: "+"; | |
float: right; | |
font-weight: bold; | |
} | |
} | |
.toggle-content { | |
color: #B0B3C2; | |
font-family: monospace; | |
font-size: 16px; | |
margin-bottom: 1.5em; | |
padding: 1em; | |
} | |
.toggle-input { | |
display: none; | |
&:not(checked) ~ .toggle-content { | |
display: none; | |
} | |
} | |
.toggle-input:checked { | |
~ .toggle-content { | |
display: block; | |
} | |
~ .toggle-label { | |
&:after { | |
content: "-"; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="toggle"> | |
<input type="checkbox" value="selected" id="beethoven-joke" class="toggle-input"> | |
<label for="beethoven-joke" class="toggle-label">What was Beethoven's favorite fruit?</label> | |
<div role="toggle" class="toggle-content"> | |
BA-NA-NA-NA! | |
</div> | |
</div> | |
<div class="toggle"> | |
<input type="checkbox" value="selected" id="army-joke" class="toggle-input"> | |
<label for="army-joke" class="toggle-label">Where did the general put his armies?</label> | |
<div class="toggle-content"> | |
Up his sleevies! | |
</div> | |
</div> | |
<div class="toggle"> | |
<input type="checkbox" value="selected" id="pepper-joke" class="toggle-input"> | |
<label for="pepper-joke" class="toggle-label">What do you call a nosy pepper?</label> | |
<div role="toggle" id="beethoven-joke" class="toggle-content"> | |
Jalapeño business! | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment