Is it possible to show and hide text using a link with only CSS -- without using JavaScript at all?
For example: On this page
Note the "More" link. When you click it, it unhides text. This particular example is JavaScript, but I am not sure if it can be done with pure CSS.
Yes, you can easily do this using CSS only. Please refer to the code below:
Maybe somebody will find this solution more intuitive and easier to implement. The mechanics of this is that the link targets itself and in that case it's easy to select anything what comes next in the DOM.
Yes, this is possible with pure CSS. You're able to click on an element by making use of a checkbox's
:checked
attribute in combination with a<label>
element'sfor
attribute.Because the checkbox can be unchecked, you can use this to toggle visibility by simply adding
visibility: hidden
to an element stemming from:checked
(once the checkbox is clicked again, this pseudo-selector will be invalid, and the CSS selector will no longer match the target).This can be extended to a
<label>
with use of thefor
attribute, so that you can completely hide the checkbox itself, and apply your own styling to the<label>
directly.The following makes use of the adjacent sibling combinator (
+
) to toggle the classtoggle
when the<label>
element is clicked: