• Resolved iroQuai

    (@stijnbiemans)


    On pc the child menu items show up on ‘mouse over’. Works like a charm! When on mobile, the menu functions very different: suddenly all the items (including the child menu items) show up, taking up all the screen estate! (especialy because i’d like to show the menu bar by default)

    how i would like it to function: On mobile, only the top level menu items are visible by default. I’d like the the child (and grandchild)-items to become visible when touching (clicking) the top level items. Is this possible through custom CSS? If so, how?

    It would be even nicer if there is a (downwards facing) triangle to indicate there is a submenu underneath the top level (that changes to an upward facing triangle when opened). And if the color of the child menu items could be blue(ish) like on PC mouse-over, that would maybe probably be nice too (at least it would be consistent with the pc-version of the menu).

    I really hope this is doable with custom CSS! thanks in advance…

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    When on mobile, the menu functions very different: suddenly all the items (including the child menu items) show up, taking up all the screen estate!

    The reason that happens is because this code is applying to your site at all browser widths:

    .panel#menu-toggle-nav {
      display: block;
    }

    Since it isn’t inside of a media query to limit its behavior to desktop views, the menu items also appear by default on the mobile/tablet views.

    how i would like it to function: On mobile, only the top level menu items are visible by default…It would be even nicer if there is a (downwards facing) triangle to indicate there is a submenu underneath the top level (that changes to an upward facing triangle when opened). And if the color of the child menu items could be blue(ish) like on PC mouse-over

    Sure, add this to your existing CSS (don’t remove the code above):

    /*Limit changes to tablet and mobile widths*/
    
    @media screen and (max-width: 48.81em) {
        /*Show only top level menu items, and set blue background on sub-menus*/
        
        .main-navigation ul ul {
            display: none;
            background-color: #7cbbbb;
        }
        /*Show down arrow for items with sub-menus*/
        
        .menu-item-has-children > a:before {
            font-family: 'Genericons';
            content: '\f502';
            display: block;
            float: left;
            width: 20px;
            height: 20px;
        }
        /*Show up arrow next to sub menu when it is open*/
        
        .menu-item-has-children > a:hover:before {
            content: '\f500';
        }
    }

    When you add the code, remember to not edit the theme files directly, otherwise your changes will be overwritten every time the theme is updated. Instead, use the CSS editor included in the Customizer as of WordPress 4.7. under Appearance > Customize > Additional CSS in your dashboard.

    Also, if you’d like to change the arrows, you can find other icons listed in the hexa > genericons > genericons.css file of your theme’s folder. If you go to GitHub (here) and download the source file zip of Genericons 3.0.3, you’ll find an example.html file there which will give you a visual preview of the different icon types available for use in Hexa.

    Thread Starter iroQuai

    (@stijnbiemans)

    that’s amazing, thank you so much!! It does exactly what I wanted. I’ve noticed the top menu items (the ones that have childeren) shouldn’t contain a link, because otherwise it opens that link on pressing and the menu closes again)

    Only thing i noticed: it’s not possible to close the submenu (feels natural to touch the top menu item again to close the submenu). Is this possible to add?

    I’m glad I could help with the earlier changes.

    it’s not possible to close the submenu (feels natural to touch the top menu item again to close the submenu). Is this possible to add?

    Hmm, so with this, I’d recommend looking for a theme that has this built in and then copying the code responsible for that behavior into a Child Theme for your site. It will likely require some JavaScript code to make it work the way you have in mind.

    Making a child theme means your changes won’t be overwritten when you update the theme. If you’re new to child themes, these resources will help you with the process:

    https://codex.www.ads-software.com/Child_Themes

    https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/

    Keeping your theme up-to-date is strongly recommended to ensure you get bug fixes, security updates, and updates to keep the theme compatible with WordPress core.

    Thread Starter iroQuai

    (@stijnbiemans)

    Hi! thanks for your thourough replies. I havn’t tried your latest suggestion. I’m actualy satisfied with the way it workes now… so this is resolved too! thanks ??

    ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Menu on mobile: Child menu items only visible after tapping?’ is closed to new replies.