SCSS : change element style if child input is checked or not
css, sass
Solution
No, there is no CSS selector that allows one to style an element based on the state of its children.
Update: The `:has()` pseudo-class was introduced in 2022, and is supported by all major browsers except Firefox as of June 2023.
You can now style parent elements based on child state like so:
label::before {
content: 'Not checked';
}
label:has(input:checked) {
background: yellow;
}
label:has(input:checked)::before {
content: 'Checked!';
}
<label>
<input type="checkbox" />
</label>
Problem
I have never used SCSS before and I would liketo know if it would allow me to style an element depending if the checkbox located inside is checked or not. For instance, I have : ``` <label> <input type="checkbox"/> </label> ``` and I would liketo change the content of `label::before` depending if the box is checked or not. Does SCSS allows things like this ? If yes,how can I do it ? The reason that led me to consider SCSS to execute this is that (if I'm not mistaking) it is indeed possible with SASS. However since I am not familiar with SASS I'd ratherdo it with SCSS, as converting my file is apparently very easy.