DEV Community

Discussion on: CSS Toggles/Switches

Collapse
 
abhishekcghosh profile image
Abhishek Ghosh

Nice. As an extension, you can actually get a hidden or stylized checkbox to maintain the toggle state and get rid of the JS entirely... A pure css only toggle.

Collapse
 
savagepixie profile image
SavagePixie • Edited

Would you mind explaining a bit more how you would go about doing that?

Collapse
 
abhishekcghosh profile image
Abhishek Ghosh

Sorry for the late reply, was inactive for a while. Basically, the idea is to maintain the toggle on/off state with a hidden checkbox's built-in checked state, and use sibling selectors to style the UI.

Something in the lines of:

.chkbox + blah {
// styles for off UI
}
.chkbox:checked + blah {
// styles for on UI
}

Thread Thread
 
savagepixie profile image
SavagePixie

Oh, that's a cool trick! Cheers!