2

My Code:

HTML:

<input id="show" type=checkbox>
<div id="content">
<p>i need help</p>
<label for="show" style="color: red;">Hide</label>
</div>
<label for="show" >read more</label>

CSS:

#show,#content{display:none;}
#show:checked~#content{display:block;}

This code will show/hide the Content when clicked on "read more" But I also want to hide the "read more" when its clicked using only css without javascript.

How can I hide it? Thanks in advance!!

#show,#content{display:none;}
    #show:checked~#content{display:block;}
<input id="show" type=checkbox>
<div id="content">
<p>Any help would be appreciated</p>
<label for="show" style="color: red;">Hide</label>
</div>
<label for="show" >read more</label>

1
  • 2
    It works exactly the same way for the label, as it did for #content - only that you want to set display:none. Commented Sep 9, 2021 at 14:12

1 Answer 1

1

Just do it like this:

#show,#content{display:none;}
#show:checked~#content{display:block;}
#show:checked~#more{display:none;}
<input id="show" type=checkbox>
<div id="content">
<p>Any help would be appreciated</p>
<label for="show" style="color: red;">Hide</label>
</div>
<label for="show" id="more">read more</label>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.