0

I am trying that when I check the box with id "expand", the rest is shown, and normally while the box is unchecked, it is not shown, but I can't get it to show, any tips or ideas?

div div p {
  display: none;
}

#expand:checked .checkbox {
  display: block;
}
<fieldset>
  <div>Pincha para recibir información:
    <input type="checkbox" class="checkbox" id="expand" value="yes">
    <div class="checkbox">
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
    </div>
  </div>

2

1 Answer 1

3

You can do it by using the sibling selector, +, and targeting the container div instead of the paragraph:

div div.checkbox {
  display: none;
}

#expand:checked + .checkbox {
  display: block;
}
<fieldset>
  <div>Pincha para recibir información:
    <input type="checkbox" class="checkbox" id="expand" value="yes">
    <div class="checkbox">
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
      <p><input type="checkbox"> Tenerife</p>
    </div>
  </div>

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.