I was looking for a pure CSS way to hide/show some form elements based on their value. Turns out it's pretty easy for checkboxes and radios. Basic example:
In the above example, I use the class .control to indicate which fields are the control and .conditional to indicate what will be displayed when the control is checked. I use sibling selectors (
~
) to tie the conditional to the control
You can get creative with IDs to show fields based on certain values only:
You can even nest them.
I haven't thought of a way to make this work with the
.conditional
in a different part of the form as it relies on an element being either a sibling or parent to be the control.