{"id":1128,"date":"2014-11-18T15:10:46","date_gmt":"2014-11-18T15:10:46","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=1128"},"modified":"2017-09-02T05:04:06","modified_gmt":"2017-09-02T05:04:06","slug":"interactive-tabs-for-email","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/interactive-tabs-for-email\/","title":{"rendered":"Interactive Tabs for Email"},"content":{"rendered":"<p><B>Update:<\/B> As of October 2016, Gmail dropped support for the :checked selector and hence this technique no longer works in Gmail.<\/p>\n<p>Wouldn&#8217;t it be cool if you could create interactive tabs that work in email? Well here&#8217;s a technique to create tabs that work in the iOS, Yahoo! Mail and AOL Mail.<BR><BR><\/p>\n<p><a href=\"https:\/\/freshinbox.com\/examples\/tabs-for-email\/\"><img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/11\/tabs-animated.gif\" alt=\"Interactive Tabs for Email\" width=\"400\" class=\"aligncenter size-full wp-image-1136\" \/><\/a><\/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>Radio inputs, labels and the :checked pseudo-class<\/h4>\n<p>Creating completely CSS driven tabs isn\u2019t new. If you google &#8220;CSS Tabs&#8221; you can find examples of <a href=\"http:\/\/css-tricks.com\/functional-css-tabs-revisited\/\" target=\"_blank\">tabs that are built with CSS<\/a>. Unfortunately these techniques don&#8217;t stand up to the ravages of <a href=\"https:\/\/freshinbox.com\/blog\/webmail-css-support-letsfixemail\/\" target=\"_blank\">Webmail&#8217;s CSS processors<\/a>.<\/p>\n<div style=\"max-width:400px;margin:20px auto;padding:10px;border:2px solid #AC88AC;text-align:center;border-radius:3px;\">\nCan&#8217;t wait to get started with interactive email?<br \/>\n<a href=\"https:\/\/freshinbox.com\/resources\/tools\/carousel\/\">Try out the Image Carousel for Email Builder<\/a>.\n<\/div>\n<p>Many of the examples use a combination of the radio input, labels and the :checked CSS3 pseudo-class.<\/p>\n<p>Here is an example of how this principle works:<\/p>\n<p><a href=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/11\/tabs-simple.gif\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/11\/tabs-simple.gif\" alt=\"Simple Tabs\" width=\"145\" height=\"88\" class=\"aligncenter size-full wp-image-1141\" \/><\/a><\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\n\/* hide radio element *\/\r\n.myradio {\r\n  display:none;\r\n  height:0px;\r\n  visibility:hidden;\r\n}\r\n.mybox {\r\n width:100px;\r\n height:50px;\r\n background-color: #eeeeee;\r\n display:none;\r\n padding:5px;\r\n}\r\n\/* change tab to bold *\/\r\n.myradio:checked + label {\r\n  font-weight: bold;\r\n} \r\n\/* show content *\/\r\n#radio1:checked ~ .box1,\r\n#radio2:checked ~ .box2\r\n{\r\n  display:block;\r\n}\r\n&lt;\/style&gt;\r\n\r\n&lt;input name=\"myradio\" type=radio id=\"radio1\" class=\"myradio\" checked&gt;\r\n&lt;label for=\"radio1\"&gt;Tab 1&lt;\/label&gt; | \r\n&lt;input name=\"myradio\" type=radio id=\"radio2\" class=\"myradio\"&gt;\r\n&lt;label for=\"radio2\"&gt;Tab 2&lt;\/label&gt;\r\n\r\n&lt;div class=\"mybox box1\"&gt;Box 1&lt;\/div&gt;\r\n&lt;div class=\"mybox box2\"&gt;Box 2&lt;\/div&gt;<\/pre>\n<p>The tab titles are wrapped within labels and placed after an associated radio input element which are styled to be hidden. The tab titles then refer to the associated radio input using the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/label\" target=\"_blank\">&#8220;for&#8221; attribute<\/a> so that clicking on the label activates the radio input with an id matching the value in the &#8220;for&#8221; attribute. That is the beauty of using radio and checkboxes and labels. We can activate any checkbox or radio element anywhere on the page by just referencing the id of the input in the &#8220;for&#8221; attribute of the label.<\/p>\n<p>Then using the :checked pseudo class and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Adjacent_sibling_selectors\" target=\"_blank\">adjacent (+)<\/a> and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/General_sibling_selectors\" target=\"_blank\">general (~)<\/a> sibling selectors, we can selectively bold the title and display the associated tabbed content.<\/p>\n<p>This fairly simple technique works on mobile and webkit based clients such as iOS and Android but in order to make it work for Webmail &#8211; we need more tricks!<BR><BR><\/p>\n<h4>Getting it to work in Webmail.<\/h4>\n<p>The problem with Webmail is that we can\u2019t use certain CSS styles.<\/p>\n<p>Yahoo! Mail strips the general sibling selector (~) as well as renders the &#8220;for&#8221; attribute useless since it renames ids and classes but not the &#8220;for&#8221; attribute. Gmail, as we know strips classes and ids which also prevents us from using the for attribute. Outlook.com doesn\u2019t support the CSS3 :checked pseudo class.<\/p>\n<p>We can support Yahoo! Mail and Gmail using three tricks:<\/p>\n<p>1) We place both the radio element and the tab content within the label. The reason for this is so we don\u2019t have to use the &#8220;for&#8221; attribute. Clicking a label automatically activates the radio element nested within.<\/p>\n<p>2) We nest labels, inputs and tab contents within each other like a set of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Matryoshka_doll\" target=\"_blank\">Russian Matryoshka dolls<\/a>. The reason we do this is so that we can leverage just the adjacent sibling selector (+) which requires that the activated and targeted elements be adjacent to each other &#8211; in this case the radio input and the span wrapper.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;label&gt;&lt;input type=radio name=\"tab\" id=\"tab1\" checked&gt;\r\n&lt;span&gt;&lt;div class=\"title1\"&gt;Tab 1&lt;\/div&gt;\r\n\r\n    &lt;!-- NESTED TAB 2 --&gt;\r\n    &lt;label&gt;&lt;input type=radio name=\"tab\" id=\"tab2\"&gt;\r\n    &lt;span&gt;&lt;div class=\"title2\"&gt;Tab 2&lt;\/div&gt;\r\n\r\n        &lt;!-- NESTED TAB 3 --&gt;\r\n        &lt;label&gt;&lt;input type=radio name=\"tab\" id=\"tab3\"&gt;\r\n        &lt;span&gt;&lt;div class=\"title3\"&gt;Tab 3&lt;\/div&gt;\r\n\r\n        &lt;div class=\"content3\"&gt;\r\n        Tab 3 Content\r\n        &lt;\/div&gt;&lt;\/span&gt;\r\n        &lt;\/label&gt;\r\n        &lt;!-- \/NESTED TAB 3 --&gt;\r\n\r\n    &lt;div class=\"content2\"&gt;\r\n    Tab 2 Content\r\n    &lt;\/div&gt;&lt;\/span&gt;\r\n    &lt;\/label&gt;\r\n    &lt;!-- \/NESTED TAB 2 --&gt;\r\n\r\n&lt;div class=\"content1\"&gt;\r\nTab 1 Content\r\n&lt;\/div&gt;&lt;\/span&gt;\r\n&lt;\/label&gt;<\/pre>\n<p><BR><\/p>\n<h4>Fallback on non supported clients.<\/h4>\n<p>Finally we need to ensure that non supported clients (Outlook, Outlook.com, Gmail) don\u2019t see a broken email. There are a few strategies to deal with this. The simplest solution is to completely hide all the tabbed content in non supported clients and that includes wrapping the tabbed content in <a href=\"https:\/\/freshinbox.com\/blog\/outlook-com-removes-all-content-within-conditional-comments\/\">Outlook conditional comments<\/a> (You didn&#8217;t seriously expect this would work in the Outlook desktop client, did you?).<\/p>\n<p>One way to hide tabbed content on clients that don&#8217;t support the :checked pseudoclass, we wrap the tabbed content with a div container and hide it, then put a checked radio input before the div and in the style block add a selector using the :checked pseudo-class to display the div container if the selector is matched.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;style&gt;\r\n.tabcheck:checked + div\r\n{\r\n  display:block !important;\r\n  max-height: none !important;\r\n  height: auto !important;\r\n}\r\n&lt;\/style&gt;\r\n\r\n&lt;input type=radio class=\"tabcheck\" style=\"display:none !important;\" checked&gt;\r\n&lt;div style=\"height:0px;max-height:0px;overflow:hidden;\"&gt;\r\nTABBED CONTENT\r\n&lt;\/div&gt;<\/pre>\n<p><BR><\/p>\n<p>Having all the content completely hidden is not ideal and a simple solution is to move Tab 1\u2019s content outside the nested tabs and have it display by default but wrap all the content within a fixed height div with an overflow of hidden. This way, when Tab 2 is activated, Tab 1\u2019s content is still displayed but no longer visible because Tab 2\u2019s content has pushed it outside of the fixed height div.<\/p>\n<p>An alternate way to deal with non-supported clients is to completely hide the tabbed content and display an alternate non-interactive layout as shown in this <a href=\"https:\/\/freshinbox.com\/blog\/shopping-in-email-add-to-cart\/\">Shopping Carousel Example<\/a>.<BR><BR><\/p>\n<h4>Final Code<\/h4>\n<p data-height=\"450\" data-theme-id=\"0\" data-slug-hash=\"xbbZNa\" data-default-tab=\"result\" data-user=\"freshinbox\" class='codepen'>See the Pen <a href='http:\/\/codepen.io\/anon\/pen\/RNVQXa\/'>RNVQXa<\/a> by FreshInbox (<a href='http:\/\/codepen.io\/freshinbox'>@freshinbox<\/a>) on <a href='http:\/\/codepen.io'>CodePen<\/a>.<\/p>\n<p><script async src=\"\/\/assets.codepen.io\/assets\/embed\/ei.js\"><\/script><\/p>\n<p>Let me know what you think!<\/p>\n<p>Hat tip to <a href=\"http:\/\/emailcodegeek.com\/\">Mark from Email Code Geek<\/a> as his email game experiments using checkboxes got me thinking about this technique for Webmail.<BR><BR><BR><\/p>\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>\n<style>\n#email-me-email {\n  width:170px;\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: 420px;\n  padding:20px;\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\/tabs-for-email\/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>Wouldn&#8217;t it be cool if you could create interactive tabs that work in email? Well here&#8217;s a technique to create tabs that work in both mobile and webmail, yes including Gmail using the <a href=\"http:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\" title=\"Make your email interactive in Gmail by using CSS attribute selectors\">Gmail lang trick<\/a>&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1173,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,24,25],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1128"}],"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=1128"}],"version-history":[{"count":70,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1128\/revisions"}],"predecessor-version":[{"id":3446,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/1128\/revisions\/3446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/1173"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=1128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=1128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=1128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}