civiltomain
civiltomain

Reputation: 1166

Select a label for input checked element at a unknown level

I have :

<div class=mystyle>
    <input type=checkbox>
    <div>
      <div>  <!---<< the label can be inside here--->
        <div>  <!---<< or here--->
         .....  <<!---< or ????--->
        </div>
       </div>
     </div>

    <div> 
    </div>       
</div>

I have a label element for that input

I want to use the checked state.

Is there any way to create a css selector connected to checked state to select it (the label) no matter where it is?.

( now I have : mystyle input:first-of-type:checked ~ div>div>div>label:hover:after but ------ )

Upvotes: 0

Views: 170

Answers (1)

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

Just try with

input:checked + div label {
    /* label style here */
}

This selector means: “pick all label elements inside a div element which is immediate sibling of a checked input

Upvotes: 1

Related Questions