Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS for show/hide div based on radio element checked/unchecked

I’m trying to show/hide a div using the following code-

<label class="paper outer">           
    <div class="inner">
                            
     </div>
      <input type="radio" name="clickedChoice">
</label>

.inner{
    position:absolute;
    width: 30px;
    right:5px;
    top:5px;
    bottom: 5px;
}

input[name="clickedChoice"] ~ .inner{ 
    display: none;
}

input[name="clickedChoice"]:checked ~ .inner{ 
    display: block !important;
}

But .inner div remains visible. What did I miss here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

<label class="paper outer">           
<input type="checkbox" name="clickedChoice">
<div class="inner">
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore minus 
consectetur assumenda ducimus aliquam minima placeat maiores natus impedit 
dolorum quod ipsam odio laboriosam, repellendus commodi, quam, saepe 
voluptatibus ad!
</div>
</label>
<style>
.inner{
position:absolute;
width: 30px;
right:5px;
top:5px;
bottom: 5px;
}

input[name="clickedChoice"] ~ .inner{ 
display: none;
}

input[name="clickedChoice"]:checked ~ .inner{ 
display: block !important;
}
</style>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading