Hybrid Collapsible Menu For Email

Update Oct 2016: With the recent Gmail update, the code was edited to prevent the menu from showing in Gmail apps (which does not support interactivity).

There has been a lot of interest in mobile menus in email ever since Jerry Martinez came out with his hamburger collapsible menu. The technique required the use of a checkbox to trigger the display and hiding of the menu.

However, a limitation of using checkboxes is that certain email service providers namely MailChimp does not support form elements in email and will strip them when the email is sent. In the same vein, some modern mobile email clients, namely Outlook on iOS does not support form elements as well.

Here’s a collapsible navigation menu for email that uses the :checked selector when available and :hover when not.

hamburger-hybrid


Hover

An alternative to using checkboxes is the use of the :hover selector. Hover has wide support on both email service providers and modern email clients. However, in certain cases the hover implementation on some clients are less reliable and glitchy than using a checkbox – particularly on the Windows 8.1 and Outlook for iOS clients.

Hybrid

Here’s a hybrid menu implementation that will use the checkbox mechanism when available, and fallback to hover when not. This way the code can be used on ESPs that don’t support form elements – though in that case, only the hover mechanism will be present in the email.

Specifically, the :hover selector below can only become active when .nav-over is a direct descendent of #navcontainer. In the original markup, .nav-over’s parent is a label, so by default, the :hover selector will not fire. However if the label is removed by the ESP or email client, then the :hover selector is enabled.

#navcontainer > .nav-over:hover + div table{
  margin-top:0% !important;
}



Code

View a live example here.

Here’s the code:
(Note -webkit-min-device-pixel-ratio was added to the media query filter to prevent it from appearing in Gmail after the updates)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Collapsible Nav using Checkbox</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body { 
  -webkit-text-size-adjust:none; 
  -ms-text-size-adjust:none; 
}
input { 
  display:none; 
}

@media (max-width:480px) and (-webkit-min-device-pixel-ratio: 0){
 #logo {height:28px !important;
   margin-top:3px;
 }
 .main-table, .main-content img { width:100% !important;}
}

@media (max-width:480px) and (-webkit-min-device-pixel-ratio: 0){

    #navcontainer{
      position:relative;
    }
    #navcontainer th{
      display:block;
      width: 100%;
      border-bottom:2px solid #ffffff;
      height:18px;
      padding: 10px 0px;      
    }
    #menucontainer{
      position:relative;
      overflow:hidden;
    }
    #navcontainer table{
      margin-top:-500px;
      -ms-transition: margin-top .5s ease-in-out;
      -webkit-transition: margin-top .5s ease-in-out;      
    }
    /* checkbox mechanism */
    #navcheckbox:checked + table{
      margin-top:0%;
    }      
    /* fallback hover mechanism */
    .nav-over,.nav-under{
     display:block !important;
     max-height:none !important;
     padding-top:3px;
     padding-bottom:3px;
    } 
    .nav-over img,.nav-under img{
     display:block;
     float:right;
     margin-right:5px;
    } 
    /*
    to deal with quirks in windows 8.1 and Outlook iOS
    */
    .nav-over{
     -ms-transition-delay: 1.5s;
     -webkit-transition-delay: 1.5s;            
    }
    #navcontainer > .nav-over:hover + div table{
      margin-top:0% !important;
    }
    #navcontainer > .nav-over:hover{
      visibility:hidden;
    }
}    
</style>
</head>
<body style="margin:0px; padding:0px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
  <td align="center">
  <table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="main-table">
    <tr>
    <td>
      <table align="left" border="0" cellpadding="10" cellspacing="0"><tr>
        <td>
          <a href="https://www.freshinbox.com/"><img id="logo" border="0" height="35" src="https://freshinbox.com/examples/hamburger-menu/images/fi-logo-large.jpg"></a>
        </td>
      </tr></table>
    </td></tr>
    <tr><td>
      <div id="navcontainer">
        <!--[if !mso 9]><!-->
        <label for="navcheckbox">
        <div class="nav-under" style="display:none;overflow:hidden;max-height:0px;background-color:#3b5369;"><img src="https://freshinbox.com/examples/hamburger-menu/images/hamburger.png" width="30" height="30" alt="Show Menu" border="0"></div>
        <div class="nav-over" style="display:none;overflow:hidden;max-height:0px;position:absolute;top:0px;width:100%;opacity:0
        "><img src="https://freshinbox.com/examples/hamburger-menu/images/hamburger.png" width="30" height="30" alt="Show Menu" border="0"></div>
        </label>
        <!--<![endif]-->
        <div id="menucontainer">
        <!--[if !mso 9]><!--><input id="navcheckbox" type="checkbox" style="display:none !important;mso-hide:all"><!--<![endif]-->
        <table cellspacing="0" cellpadding="0" border="0" width="100%" bgcolor="#3b5369" style="width:100% !important">
            <tr>
            <th height="25" align="center" valign="center"><a href="https://freshinbox.com/blog" target="_blank" style="font-size:15px;font-family:arial,sans-serif;color:#ffffff;font-weight:bold;text-decoration:none;">Blog</a></th>
            <th height="25" align="center"><a href="https://freshinbox.com/blog/category/interactive-email-tutorial/" target="_blank" style="font-size:15px;font-family:arial,sans-serif;color:#ffffff;font-weight:bold;text-decoration:none;">Interactive Email</a></th>
            <th height="25" align="center"><a href="https://freshinbox.com/blog/tools/" target="_blank" style="font-size:15px;font-family:arial,sans-serif;color:#ffffff;font-weight:bold;text-decoration:none;">Tools</a></th>            
            <th height="25" align="center"><a href="https://freshinbox.com/blog/about/" target="_blank" style="font-size:15px;font-family:arial,sans-serif;color:#ffffff;font-weight:bold;text-decoration:none;">About</a></th>
            </tr>
        </table>
        </div>
      </div><BR>
      <table cellspacing="0" cellpadding="0" border="0" width="100%" class="main-content"><tr><td>
      <img src="https://freshinbox.com/examples/hamburger-menu/images/hero.png" width="600">
      </td></tr><tr>
      <td style="font-size:18px;font-family:arial,sans-serif;color:#555555;padding:20px;"><BR>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet tortor elit. Donec faucibus mattis nulla eu viverra. Integer ac mattis massa. Vivamus sollicitudin urna vitae bibendum interdum. Vivamus eget lobortis neque. Suspendisse fringilla ante vitae est aliquet, at ornare nunc posuere. Duis venenatis ligula et nunc accumsan, vitae egestas leo pulvinar. 
      </td></tr></table>
      </td>
      </tr>
  </table>
  </td>
  </tr>
</table>
</body>
</html>



Feedback

I’d love to hear your experiements with navigation menus and what other quirks you have encountered while using them.





Subscribe to the #EmailGeeks Newsletter


Latest Comments
  1. Jeff

    Awesome, thanks for this!

  2. Tony

    The collapsible menu works fine in IOS, but I noticed that there’s extra spacing between the menu bar and the content following when viewing it on an Android device. Not sure why that is, your thoughts?

  3. Marjolein

    Thanks for the code!
    I did another update to remove the navigation in Gmail/Inbox altogether (because my clients always want way too many items in their navigation – it would push apart the mail in Gmail).

    So I used the update seen in the EmailonAcid webinar about Gmail updates and added:

    u + .body #navcontainer {
    display: none !important;
    }

    (gave the body tag a class = body)

  4. Marjolein

    It seems the Outlook.com app has received an update that now breaks this code. Even with the media query set to webkit only (@media (max-width:480px) and (-webkit-min-device-pixel-ratio: 0)) it shows both the hamburger images AND a dropped down navigation. I can live with the navigation shown completely I guess, but any idea how to hide the hamburger images?

    I’m testing on an Android, but know it’s also an issue on iOS.

    • Jaemi

      You could remove the nav-over div, and then you’ll only see one set of lines in Outlook on mobile. You’d have to test to make sure it didn’t break anything anywhere else you care about, but from my preliminary testing, it didn’t break the menu. Frustrating. Outlook mobile considers itself webkit. So you can’t really hide from it without losing the whole thing. But if it’s webkit, it ought to work….

Leave a Reply

Your email address will not be published. Required fields are marked *