Bumping this, because I'm currently updating some templates anyway and there's a better way of doing it. Namely, buttons instead of anchors (or spans).
Advantages are:
This is also used with js. IOW, one bit of CSS does the lot. This trick could not be used with ancient browsers, but has had full support for some time (except IE, but IE can have hover fallback). It works brilliantly. It can still be improved slightly when js is available*, but doesn't need it to give full functionality for everyone.
*The improvements are obviously:
Advantages are:
- Better semantics.
- No need for role="button" (which the phpBB anchors and spans don't have, even though they really should).
- No need for a href, which further simplifies markup (and also means no page jumping if anyone accidentally clicks when js is disabled).
- Mouse activation will work exactly the same way with or without javascript.
- Full keyboard accessibility, without javascript being required.
- Automatic click outside to close, without javascript being required.
- Automatic closing when you tab out of the drop menu (if using keyboard nav).
This is also used with js. IOW, one bit of CSS does the lot. This trick could not be used with ancient browsers, but has had full support for some time (except IE, but IE can have hover fallback). It works brilliantly. It can still be improved slightly when js is available*, but doesn't need it to give full functionality for everyone.
*The improvements are obviously:
- to keep drop menu content hidden unless the button is actually selected by click/tap/Enter and
- to alter the button behaviour to also allow closing the drop menu by by click/tap/Enter (which is not possible without js).
Statistics: Posted by Gumboots — Sun Jul 21, 2024 12:25 am