I'm working on getting a mobile hamburger navigation to work, but I'm having trouble applying CSS to the element due to nesting/relation of the elements. I have the hamburger icon (#mobile-menu
) animating properly based on the input (#nav-trigger
) being checked or not (turns into an X).
But when #nav-trigger
is checked, i also want to change the absolute positioning of #header-nav
(bringing it into view when checked). This is where I'm stuck. How do i use CSS selectors to apply a CSS rule change to #header-nav
when #nav-trigger
is checked? I'm using SCSS and i've tried nesting selectors like ~
, +
, and more but i can't get it to work. Any help is greatly appreciated. Thank you!
<nav id="header-nav">
<ul>
<li>
<a>Nav item</a>
</li>
<li>
<a>Nav item</a>
</li>
<!-- etc... -->
</ul>
</nav>
<div id="mobile-menu-container">
<div id="mobile-menu-div">
<label id="mobile-menu-label" for="nav-trigger"></label>
<input type="checkbox" id="nav-trigger"/>
<div id="mobile-menu"></div>
</div>
</div>