Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

styling an element when checkbox is checked

Tags:

css

<input type="checkbox" id="c1">
<label for="c1">c1</label>
<div>
    <span></span>
    <span></span>
</div>

I want to style span when checkbox is checked. I tried below style but its not working.

input:checked ~ div span{
    background: red;
}

input:checked~div span {
  background: red;
}
<input type="checkbox" id="c1">
<label for="c1">c1</label>
<div>
  <span></span>
  <span></span>
</div>
like image 784
Mayur Punjabi Avatar asked Dec 18 '22 22:12

Mayur Punjabi


1 Answers

Put some content inside your span, it's working.

input:checked ~ div span{
    background: red;
}
<input type="checkbox" id="c1">
<label for="c1">c1</label>
<div>
    <span>Red Text</span>
    <span>Red alert</span>
</div>
like image 99
Mr. Roshan Avatar answered May 05 '23 07:05

Mr. Roshan