I have these elements :
<label class="tog" for="toggle">☰</label>
<input type="checkbox" id="toggle">
<ul class="tabs">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Organizations</a></li>
<li><a href="#">Take Action</a></li>
<li><a href="#">Resourses</a></li>
<li><a href="#">Contact</a></li>
</ul>
and the css :
.tabs{display:none}
#toggle:checked+ .tabs{
display:block
}
I also tried :
#toggle:checked~ .tabs{
display:block
}
But it still doesn't show up the hidden <ul class="tabs">
Target your input instead.
.tabs { display: none; } input[type=checkbox]:checked ~ .tabs{ display: block; }
<label class="tog" for="toggle">☰</label> <input type="checkbox" id="toggle"> <ul class="tabs"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Organizations</a></li> <li><a href="#">Take Action</a></li> <li><a href="#">Resourses</a></li> <li><a href="#">Contact</a></li> </ul>
Try this.
.tabs{
display:none
}
#toggle:checked + .tabs{
display:block
}
The spacing makes a difference.
.tabs {
display: none;
}
#toggle:checked + .tabs {
display: block;
}
This is working for me.
Because demo snippets cannot be inserted into comments...
Your code works , test snippets below :
#toggle:checked + .tabs{
display:block
}
.tabs{display:none} #toggle:checked + .tabs{ display:block }
<label class="tog" for="toggle">☰</label> <input type="checkbox" id="toggle"> <ul class="tabs"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Organizations</a></li> <li><a href="#">Take Action</a></li> <li><a href="#">Resourses</a></li> <li><a href="#">Contact</a></li> </ul>
#toggle:checked ~ .tabs{
display:block
}
.tabs { display: none } #toggle:checked~.tabs { display: block }
<label class="tog" for="toggle">☰</label> <input type="checkbox" id="toggle"> <ul class="tabs"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Organizations</a></li> <li><a href="#">Take Action</a></li> <li><a href="#">Resourses</a></li> <li><a href="#">Contact</a></li> </ul>
Your problem stands else where :( Please clarify question with bits of codes that actually shows your issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.