hide spoilers using CSS ::selection pseudo class
posted on December 29, 2020, 12:02 pm in
Often times you'll have some text you want to hide from your readers as spoilers, with CSS you can hide this easily. Using ::selection pseudo class, keep text hidden until a user selects it.
The CSS;
.hide-this { color: rgb(74, 74, 74); background: rgb(74, 74, 74) }
.hide-this::selection { color: black; background: white; }
and the HTML;
<div>the secret to understanding the universe is <span class="hide-this">to remember to dance and to keep yourself moving</span>.<div>
Heres a demo; the secret to understanding the universe is
. Use your mouse to select the hidden line and reveal the secret.recent posts
- Weekend Project: Online Javascript Code Editor December 18, 2022
- adding a dark mode toggle to any website November 08, 2022
- add styled tooltips using vanilla javascript November 13, 2021
find something helpful? send us some coin BTC 19u6CWTxH4cH9V2yTfAemA7gmmh7rANgiv
(ad) Need Hosting? Try Linode, VPS Starting from $5