I have a two-level navigation menu implemented with the :focus-within pseudo class. On small devices it should appear as a 'Menu' button at the bottom of the screen, which expands to the first level on tapping. The second level should open on tapping a first-level item and the first level should (of course) remain open. This works fine on Android phones but my iPhone users report that the Menu button does not respond to tapping.
Here's the HTML snippet:
<div class="gcc-expands" id="GCCmainNav">
<a href="#" id="GCCnavOpen">☰ Menu</a>
<div class="gcc-expansion">
<nav role="navigation"class="gcc-menu">
<a href="/">Home</a>
<a href="/#GCCprogramme">Concerts & Events</a>
<div class="gcc-expands">
<a href="#">About Us</a>
<div class="gcc-expansion">
<div class="gcc-menu" id="GCCaboutNav">
<a href="/about-us.php">The Choir</a>
<a href="/#GCCrecordings">The Choir on CD</a>
<a href="/history.php">History</a>
<a href="/contact-us.php#GCCcontact">Contact</a>
</div>
</div>
</div>
<a href="/for-members/members1.php">For Members</a>
</nav>
</div>
</div>
And here's the CSS:
.gcc-expands {
position: relative;
}
.gcc-expansion {
display: none;
position: relative;
}
.gcc-expands:focus-within>.gcc-expansion {
display: block;
}
Focussing on the #GCCnavOpen pseudo link should cause the first level .gcc-expansion to display, then focussing on the 'About Us' link should keep the first level open (:focus-within) and open the inner .gcc-expansion.
According to caniuse, this has been supported in iOS Safari since 10.3 (2017) but it doesn't seem to be working for my users. Any insights, please?
display: block
(or whatever) to a parent while it or the child had focus. In that respect, it's a unique CSS feature -- no other selector allows you to style a parent based on the state of a child. I'm glad to say that I have now solved the problem and I'll post a new comment about that.