This question has already been answered:
- Left neighbor selector 3 answers
Greetings. In the example, I used input type="radio" to select "show", "close" some block. How to make the active radio change the background, i.e. lightgreen changed to green , it turned out with red (the colors on the contrary are true, but it is not scary), because it is the next element, and green is obtained as the previous element, so how to choose the previous element to change the background while :checked ? Thank!
body{z-index:10;positioin:relative;text-align:center;} input{display:none;}/*радио кнопки*/ label[for="radio-1"]{background:lightgreen;} label[for="radio-2"]{background:pink;} label{ cursor:pointer; border:1px solid #333; padding:5px; margin-top:20px; display:inline-block; } label:hover{opacity:0.6;} label:active{background:rgba(0,0,0,0.2);} .block{ width:600px; position:absolute; top:80px; left:28%; } #radio-1:checked ~ .block{display:block;} .block{display:none;} #radio-1:checked ~ label{background:red;} <label class="green" for="radio-1">OPEN<sup>(chckd)</sup></label> <input type="radio" name="radio" id="radio-1" checked="checked"> <label class="red" for="radio-2">CLOSE</label> <input type="radio" name="radio" id="radio-2"> <!-- --> <!-- --> <div class="block"> <fieldset> <legend>HEADER</legend> <h1>TEXT-HEADER #1 <strong>...some text</strong></h1> </fieldset> </div>