Skip to content Skip to sidebar Skip to footer

Css&html Nav Bar Should Appear When Checkbox Is Checked

I've tried using the two sibling selectors (~, as in snippet, and +) to make the nav bar appear when the box is checked, but it doesn't work, nor do I know what else to do.

Solution 1:

Here is what you code should look like, first you have a none closed <div> tag and for + sibling select move the label for the above the checkbox.

nav{
    left: -100%;
    position: fixed;

}

#check:checked + nav{
    left: 0px;
}
<labelfor="check"><iclass="fas fa-bars"></i></label><inputtype="checkbox"id="check"><nav><ul><li><ahref="">Test</a></li><li><ahref="">Test</a></li><li><ahref="">Test</a></li></ul></nav>

and if you want to have the same order for the tag change the CSS selector to this:

nav{
    left: -100%;
    position: fixed;
}

#check:checked + label + nav{
    left: 0px;
}
<inputtype="checkbox"id="check"><labelfor="check"><iclass="fas fa-bars"></i></label><nav><ul><li><ahref="">Test</a></li><li><ahref="">Test</a></li><li><ahref="">Test</a></li></ul></nav>

Post a Comment for "Css&html Nav Bar Should Appear When Checkbox Is Checked"