/* BeejBløg */

Jun 3, 2018 - 1 minute read - Comments -

Minimal Pure CSS Expand/Collapse Widget

The gist here is leveraging a hidden checkbox to maintain expand/collapse state and css :before {content: "xyz" } to add the expand/collapse widget which keeps the additional markup minimal.

Markdown compatible :)

<p></p><input type="checkbox" class="expander">
#### Expandified Heading
* bullet 
* bullet
* <input type="checkbox" class="expander"><i>another expander</i>
  * nested content that will be expanded

yeah i know, what’s up with the the extra <p> tag pal?! those sprinkles on my minimalist day parade are the only way i could get my blog’s markdown renderer (Hugo > “Blackfriday”) to not mangle the expander input under a p tag which ruins using css sibling selector used target the show/hide content

Demo post (rendered via Markdown)

Not an original idea … just boiling it down for my specific usage

For the record, it’s not valid html to apply :before/after psuedo elements to form elements like <input> because they’re not technically “content” (stack-o reference), bummer… webkit (chrome, safari) actually do render directly on <input> but firefox & explorer don’t… oh well, it’s not much more to rely on one more element right after <input>… i’m using the <i> tag as popularized by font-awesome but this is arbitrary.

Look ma, no JS! :)

Previous 2015-07-18 jQuery based solution: