Recently I had a need to add a very simple bit of functionality to my blog that would show/hide some bbcode
examples. I didn't want to use Bootstrap/jQuery
for such a simple task so I looked around and found this simple CSS
trick that does exactly what I need by using a checkbox
to trigger showing/hiding a pre
element, effectively simulating a Bootstrap Accordion
Here's what it looks like...
The CSS is very simple:
To explain this - the :checked
pseudo-class applies when the checkbox is selected/checked and the '+ pre'
part is an adjacent selector for the pre element. Together this means 'when there is a checked checkbox next to a pre element'
Now the HTML is like this...
As long as the pre
element is immediately after the checkbox
You can also replace the pre
element with just about anything else, as long as the style is updated and you use the new element after the checkbox
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...