One clever solution using only CSS involves the checkbox
hack
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
opacity: 0;
}
div {
position: relative;
}
label {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
}
input[type=checkbox]:checked ~ div {
background: magenta;
}
<input type="checkbox" id="checkMeOut">
<div>
<label for="checkMeOut">test</label>
i will change background-color
</div>
First, set up the HTML (checkbox input, the div you want to change, inside the div add a label linked to your checkbox)
Second, in the CSS, hide the checkbox in any way you want.
Position the label absolutely, giving it a height and width equal to the div's dimensions so when you click anywhere on the div, you click on the label and thus activate the checkbox giving it :checked
status
Then, using the general sibling connector ~
, give any style you want to the div
Let me know if it works for you