{"id":1920,"date":"2015-09-29T16:52:50","date_gmt":"2015-09-29T16:52:50","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=1920"},"modified":"2016-10-15T23:03:45","modified_gmt":"2016-10-15T23:03:45","slug":"hybrid-collapsible-menu-for-email","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/hybrid-collapsible-menu-for-email\/","title":{"rendered":"Hybrid Collapsible Menu For Email"},"content":{"rendered":"<p><i><B>Update Oct 2016:<\/B> With the <a href=\"https:\/\/www.emailonacid.com\/blog\/article\/industry-news\/gmail-update-embedded-styles-and-media-queries\">recent Gmail update<\/a>, the code was edited to prevent the menu from showing in Gmail apps (which does not support interactivity).<\/i><\/p>\n<p>There has been a lot of interest in mobile menus in email ever since Jerry Martinez came out with his <a href=\"https:\/\/freshinbox.com\/blog\/hamburger-collapsible-menu-in-email\/\">hamburger collapsible menu<\/a>. The technique required the use of a checkbox to trigger the display and hiding of the menu.<\/p>\n<p>However, a limitation of using checkboxes is that <a href=\"https:\/\/freshinbox.com\/resources\/esp-support.php\">certain email service providers<\/a> namely MailChimp does not support form elements in email and will strip them when the email is sent. In the same vein, <a href=\"https:\/\/freshinbox.com\/resources\/css.php\">some modern mobile email clients<\/a>, namely Outlook on iOS does not support form elements as well.<\/p>\n<p>Here&#8217;s a collapsible navigation menu for email that uses the :checked selector when available and :hover when not. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2015\/09\/hamburger-hybrid.jpg\" alt=\"hamburger-hybrid\" width=\"250\" class=\"aligncenter size-full wp-image-2175\" \/><\/p>\n<div id=\"email-me\">\n  <input type=email id=\"email-me-email\" placeholder=\"Email address\"> <input id=\"email-me-btn\" type=button value=\"See Example In Your Inbox\" style=\"-webkit-appearance: none;\">\n<\/div>\n<p><BR><\/p>\n<h4>Hover<\/h4>\n<p>An alternative to using checkboxes is the use of the :hover selector. Hover has <a href=\"https:\/\/freshinbox.com\/resources\/css.php\">wide support<\/a> 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 &#8211; particularly on the Windows 8.1 and Outlook for iOS clients.<BR><BR><\/p>\n<h4>Hybrid<\/h4>\n<p>Here&#8217;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&#8217;t support form elements &#8211; though in that case, only the hover mechanism will be present in the email.<\/p>\n<p>Specifically, the :hover selector below can only become active when .nav-over is a direct descendent of #navcontainer. In the original markup, .nav-over&#8217;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.<\/p>\n<pre class=\"lang:default decode:true \" >#navcontainer &gt; .nav-over:hover + div table{\r\n  margin-top:0% !important;\r\n}<\/pre>\n<p><BR><BR> <\/p>\n<h4>Code<\/h4>\n<p><b>View a <a href=\"http:\/\/codepen.io\/freshinbox\/pen\/ORoVNy\">live example here<\/a><\/b>.<\/p>\n<p>Here&#8217;s the code:<br \/>\n(Note -webkit-min-device-pixel-ratio was added to the media query filter to prevent it from appearing in Gmail after the updates)<\/p>\n<pre class=\"toolbar:1 height-set:true width:450 lang:default decode:true \" >&lt;!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"&gt;\r\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Collapsible Nav using Checkbox&lt;\/title&gt;\r\n&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"&gt;\r\n&lt;meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"&gt;\r\n&lt;style&gt;\r\nbody { \r\n  -webkit-text-size-adjust:none; \r\n  -ms-text-size-adjust:none; \r\n}\r\ninput { \r\n  display:none; \r\n}\r\n\r\n@media (max-width:480px) and (-webkit-min-device-pixel-ratio: 0){\r\n #logo {height:28px !important;\r\n   margin-top:3px;\r\n }\r\n .main-table, .main-content img { width:100% !important;}\r\n}\r\n\r\n@media (max-width:480px) and (-webkit-min-device-pixel-ratio: 0){\r\n\r\n    #navcontainer{\r\n      position:relative;\r\n    }\r\n    #navcontainer th{\r\n      display:block;\r\n      width: 100%;\r\n      border-bottom:2px solid #ffffff;\r\n      height:18px;\r\n      padding: 10px 0px;      \r\n    }\r\n    #menucontainer{\r\n      position:relative;\r\n      overflow:hidden;\r\n    }\r\n    #navcontainer table{\r\n      margin-top:-500px;\r\n      -ms-transition: margin-top .5s ease-in-out;\r\n      -webkit-transition: margin-top .5s ease-in-out;      \r\n    }\r\n    \/* checkbox mechanism *\/\r\n    #navcheckbox:checked + table{\r\n      margin-top:0%;\r\n    }      \r\n    \/* fallback hover mechanism *\/\r\n    .nav-over,.nav-under{\r\n     display:block !important;\r\n     max-height:none !important;\r\n     padding-top:3px;\r\n     padding-bottom:3px;\r\n    } \r\n    .nav-over img,.nav-under img{\r\n     display:block;\r\n     float:right;\r\n     margin-right:5px;\r\n    } \r\n    \/*\r\n    to deal with quirks in windows 8.1 and Outlook iOS\r\n    *\/\r\n    .nav-over{\r\n     -ms-transition-delay: 1.5s;\r\n     -webkit-transition-delay: 1.5s;            \r\n    }\r\n    #navcontainer &gt; .nav-over:hover + div table{\r\n      margin-top:0% !important;\r\n    }\r\n    #navcontainer &gt; .nav-over:hover{\r\n      visibility:hidden;\r\n    }\r\n}    \r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body style=\"margin:0px; padding:0px;\"&gt;\r\n&lt;table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"&gt;\r\n&lt;tr&gt;\r\n  &lt;td align=\"center\"&gt;\r\n  &lt;table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"main-table\"&gt;\r\n    &lt;tr&gt;\r\n    &lt;td&gt;\r\n      &lt;table align=\"left\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\"&gt;&lt;tr&gt;\r\n        &lt;td&gt;\r\n          &lt;a href=\"https:\/\/www.freshinbox.com\/\"&gt;&lt;img id=\"logo\" border=\"0\" height=\"35\" src=\"https:\/\/freshinbox.com\/examples\/hamburger-menu\/images\/fi-logo-large.jpg\"&gt;&lt;\/a&gt;\r\n        &lt;\/td&gt;\r\n      &lt;\/tr&gt;&lt;\/table&gt;\r\n    &lt;\/td&gt;&lt;\/tr&gt;\r\n    &lt;tr&gt;&lt;td&gt;\r\n      &lt;div id=\"navcontainer\"&gt;\r\n        &lt;!--[if !mso 9]&gt;&lt;!--&gt;\r\n        &lt;label for=\"navcheckbox\"&gt;\r\n        &lt;div class=\"nav-under\" style=\"display:none;overflow:hidden;max-height:0px;background-color:#3b5369;\"&gt;&lt;img src=\"https:\/\/freshinbox.com\/examples\/hamburger-menu\/images\/hamburger.png\" width=\"30\" height=\"30\" alt=\"Show Menu\" border=\"0\"&gt;&lt;\/div&gt;\r\n        &lt;div class=\"nav-over\" style=\"display:none;overflow:hidden;max-height:0px;position:absolute;top:0px;width:100%;opacity:0\r\n        \"&gt;&lt;img src=\"https:\/\/freshinbox.com\/examples\/hamburger-menu\/images\/hamburger.png\" width=\"30\" height=\"30\" alt=\"Show Menu\" border=\"0\"&gt;&lt;\/div&gt;\r\n        &lt;\/label&gt;\r\n        &lt;!--&lt;![endif]--&gt;\r\n        &lt;div id=\"menucontainer\"&gt;\r\n        &lt;!--[if !mso 9]&gt;&lt;!--&gt;&lt;input id=\"navcheckbox\" type=\"checkbox\" style=\"display:none !important;mso-hide:all\"&gt;&lt;!--&lt;![endif]--&gt;\r\n        &lt;table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" bgcolor=\"#3b5369\" style=\"width:100% !important\"&gt;\r\n            &lt;tr&gt;\r\n            &lt;th height=\"25\" align=\"center\" valign=\"center\"&gt;&lt;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;\"&gt;Blog&lt;\/a&gt;&lt;\/th&gt;\r\n            &lt;th height=\"25\" align=\"center\"&gt;&lt;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;\"&gt;Interactive Email&lt;\/a&gt;&lt;\/th&gt;\r\n            &lt;th height=\"25\" align=\"center\"&gt;&lt;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;\"&gt;Tools&lt;\/a&gt;&lt;\/th&gt;            \r\n            &lt;th height=\"25\" align=\"center\"&gt;&lt;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;\"&gt;About&lt;\/a&gt;&lt;\/th&gt;\r\n            &lt;\/tr&gt;\r\n        &lt;\/table&gt;\r\n        &lt;\/div&gt;\r\n      &lt;\/div&gt;&lt;BR&gt;\r\n      &lt;table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" class=\"main-content\"&gt;&lt;tr&gt;&lt;td&gt;\r\n      &lt;img src=\"https:\/\/freshinbox.com\/examples\/hamburger-menu\/images\/hero.png\" width=\"600\"&gt;\r\n      &lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;\r\n      &lt;td style=\"font-size:18px;font-family:arial,sans-serif;color:#555555;padding:20px;\"&gt;&lt;BR&gt;\r\n      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. \r\n      &lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;\r\n      &lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n  &lt;\/table&gt;\r\n  &lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><BR><BR><\/p>\n<h4>Feedback<\/h4>\n<p>I&#8217;d love to hear your experiements with navigation menus and what other quirks you have encountered while using them.<\/p>\n<p><BR><BR><BR><br \/>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div><\/p>\n<style>\n#email-me-email {\n  width:150px;\n  height:20px;\n  margin-bottom: 5px;\n  background-color: #FAFCEF;\n  font-size: 14px;\n  padding: 3px 5px;\n  display:inline-block;\n  border-radius:3px;\n  margin-left:20px;\n}\n#email-me-btn {\n  cursor: pointer;\n  font-size: 14px;\n  color: white;\n  text-decoration:none;\n  text-shadow:#555555 0 1px;\n  background-color: #7DC442;\n  padding: 5px 12px;\n  border:1px solid #559621;\n  border-radius: 5px;\n  display:inline-block;\n}\n#email-me-btn:hover {\n  background-color: #78D62C;\n}\n#email-me{\n  width: 400px;\n  padding:20px 0px;\n  xborder:3px solid #888888;\n  xborder-radius: 5px;\n  margin:0px auto;\n}\n<\/style>\n<p><script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.10.2\/jquery.min.js\"><\/script><br \/>\n<script>\n  var theEmail = null;\n  $(document).ready(function(){\n    $('#email-me-btn').click(function(){\n      theEmail = $('#email-me-email').val();\n      sendEmail(theEmail);\n    });\n    $(\"#email-me-email\").keypress(function(e) {\n      if(e.which == 13) {\n        theEmail = $('#email-me-email').val();        \n        sendEmail(theEmail);\n      }\n    });\n  });\n  var sendEmail = function(emailAddr){\n    if(!emailAddr || emailAddr.length < 12){\n      alert('Please enter an email');\n      return;\n    }\n    $('#email-me-email').val('sending...');\n    $.ajax({\n      url: \"https:\/\/freshinbox.com\/examples\/hamburger-menu\/mail_example.php\",\n      data: {\n        email: emailAddr\n      },\n      success: function( data ) {\n        if(data == null || data.indexOf(\"ERROR\") != -1){\n          alert(\"There was a problem sending the email \\n\"+data);\n        }else{\n          alert(\"An email has been sent to \"+emailAddr+\"!\\n (Be sure to check the spam folder just in case)\");          \n        }\n        $('#email-me-email').val('');\n      }\n    });\n  }\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a collapsible navigation menu for email that uses the :checked selector when available and :hover when not. Certain email clients as well as email service providers don&#8217;t support checkboxes in email so when checkboxes are stripped, this technique continues to work in clients that only support the :hover selector.<\/p>\n","protected":false},"author":2,"featured_media":2174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,24],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1920"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=1920"}],"version-history":[{"count":33,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1920\/revisions"}],"predecessor-version":[{"id":2204,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1920\/revisions\/2204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/2174"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=1920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=1920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=1920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}