Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

(Pure CSS) Expand/collapse objects WITHOUT JAVASCRIPT

I wrote this for some project I'm working on and recommended it be used for the menu here on the top left of the form for non-js compatibility, so I figured I'd post it here.

Here's all the CSS you need:
Spoiler (Click to View)

And some html:
Spoiler (Click to View)

You may be able to substitute input[type=checkbox]:checked for #collapseobj:checked to use with multiple checkboxes, but I haven't tested this (though it is working here https://codepen.io/tomasz86/pen/wuzcK)

What's going on here?  Well, we're using the checkbox hack.  When the checkbox (which we give content to with css) is clicked, it will change the css of the collapseobj class, back and forth.

Now, I haven't positioned the button in that short little html snippet so you'll have to do it yourself.  But that's how it's done.

I've found using opacity fading with the animation makes it appear a little smoother.

Hope you all can employ this cool css trick and get rid of your JS! 🎉
Does anyone want to mine bitcoin with me in 2011?
Great little nugget thanks for the share! Barely any CSS + no JS too, what a bonus.
Web Designer / Developer & SEO Expert.

View Work
Earn 10% of the job you refer me to!

Skype aerox.design


yeah this is a nice trick, I often use this to make dropdown/hamburger-menus without JS
[Image: AAjOYL.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Wordpress] by StumailSep 14, 2021 12:29 PM 1 109 Sep 14, 2021 12:29 PM
Last Post: Stumail
by R3gulateSep 27, 2019 10:06 AM 4 180 Sep 27, 2019 10:06 AM
Last Post: ramifenili
by Kaz'jinJan 14, 2018 02:29 PM 2 428 Jan 14, 2018 02:29 PM
Last Post: Kaz'jin