Last Updated: August 05, 2019
·
4.352K
· timpietrusky

Advanced Checkbox Hack

Do you know the default checkbox hack?

HTML

<label for="toggle-1">Do Something</label>
<input type="checkbox" id="toggle-1">
<div>Control me</div>

CSS

input[type=checkbox] {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

div {
  background: green;
}

input[type=checkbox]:checked ~ div {
  background: red;
}

Problem

This hack is not working on (older) iOS and (up to date) Android.

Solution

How do we fix this? Read more about this in my article Advanced Checkbox Hack!

1 Response
Add your response

@duiker101 You can create something with two states: not checked and checked in pure CSS and don't need to add JavaScript. For example a responsive menu and the hack opens/closes it.

over 1 year ago ·