Skip to content

Instantly share code, notes, and snippets.

@LeaVerou
Last active December 9, 2017 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeaVerou/24c756eb35a67e34d7a9 to your computer and use it in GitHub Desktop.
Save LeaVerou/24c756eb35a67e34d7a9 to your computer and use it in GitHub Desktop.
Pure CSS, accessible like button (inspired by Medium)
/**
* Pure CSS, accessible like button (inspired by Medium)
*/
.like {
position: absolute;
clip: rect(0,0,0,0);
}
.like + label {
display: inline-block;
height: 1.5em;
overflow: hidden;
user-select: none;
}
@keyframes beat { from {
transform: scale(.5);
opacity: 0;
} }
@keyframes beat2 { from {
transform: scale(.5);
opacity: 0;
} }
.like + label::before {
content: "♡";
display: block;
width: min-content;
font: bold 150%/1 Helvetica Neue, Helvetica, sans-serif;
color: #00ab6b;
animation: beat .3s cubic-bezier(.1,.7,.6,1.5);
}
.like:checked + label::before {
content: "♥";
animation-name: beat2;
}
<input type="checkbox" id="like" class="like" />
<label for="like">I like this</label>
<input type="checkbox" id="like2" class="like" checked />
<label for="like2">I like this</label>
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment