|
|
|
|
|
by glacials
1633 days ago
|
|
Now that it's 2021, most of the concessions the author makes are possible with CSS. You can change the styling of an element using hyperlinks with the `target` pseudo selector: <style>
#dropdown {
display: none;
}
#dropdown:target {
display: block;
}
</style>
<a href="#dropdown">Show dropdown</a>
<div id="dropdown">
Dropped down!
<a href="#">Close</a>
</div>
This works for dropdowns, tooltips, modals, even navigation if you're navigating to known places (or if you use JS to pre-insert the destination into the DOM). And of course, you can animate the changes with pure CSS. |
|
The better hack that has been long available is invisible checkboxes, :checked and a sibling selector. That’s almost certainly what “you could fake it with CSS too” was describing back then.
But the proper solution now would be <details>. As an example of this, many dropdowns on GitHub work without JavaScript, by using <details>.
I would note that with all of these alternatives, you tend to want a little JavaScript to enhance the functionality, e.g. manage ARIA states and focus.