Skip to content

Instantly share code, notes, and snippets.

@JaneOri
Created March 14, 2019 17:13
Show Gist options
  • Save JaneOri/79cb470c4bd79d2464e17dc26ce2db5b to your computer and use it in GitHub Desktop.
Save JaneOri/79cb470c4bd79d2464e17dc26ce2db5b to your computer and use it in GitHub Desktop.
CSS "Tristate with hold" Like (off) / Liked (on) / Unlike (on & hover, but not right away)

via: https://twitter.com/mikesherov/status/1106187591529975810

CSS challenge: make a pure CSS “tristate with hold” toggle

Requirements:
1. If off, show “like”
2. If on + no hover, show “liked”
3. If on + hover, show “unlike”
4. (The twist!) Right after toggling on, before unhovering, show “liked”
.tristate-like:after {
content: "Like";
padding-left: 15px;
}
@keyframes unlike {
0% { --unlike: "Liked"; }
100% { --unlike: "Unlike"; }
}
.tristate-like:checked:after {
content: "Liked";
animation: unlike var(--time, 0s) step-end forwards;
}
.tristate-like:hover:checked:after {
content: var(--unlike);
--time: 1.0s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment