{"id":346,"date":"2014-02-10T11:38:45","date_gmt":"2014-02-10T11:38:45","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=346"},"modified":"2015-07-30T22:38:10","modified_gmt":"2015-07-30T22:38:10","slug":"image-rollovers-for-mobile-and-non-mobile-email","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/image-rollovers-for-mobile-and-non-mobile-email\/","title":{"rendered":"Image Rollovers for Mobile and Non-Mobile Email"},"content":{"rendered":"<p>In previous articles we saw how we can implement interactive image rollovers for either <a href=\"https:\/\/freshinbox.com\/blog\/3-steps-to-create-an-interactive-email-using-css\/\">webmail<\/a> or <a href=\"https:\/\/freshinbox.com\/blog\/interactive-images-on-mobile-email\/\">mobile email<\/a>.<\/p>\n<p>This tutorial will go over how we can combine both techniques for an image rollover example that works with mobile and non-mobile email clients &#8211; (except the usual suspects &#8211; Gmail and Outlook 2007+).<\/p>\n<p><strong>Update:\u00a0<\/strong>Here&#8217;s a tool to create the non-mobile example: <a title=\"Rollover Image Builder for Email\" href=\"https:\/\/freshinbox.com\/blog\/rollover-images-revisited\/\">Rollover Image Builder for Email<\/a>.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/01\/switch-bottom1.jpg\" \/><\/p>\n<h4>Table Background and image hover<\/h4>\n<p>Lets start with the <a href=\"https:\/\/freshinbox.com\/blog\/interactive-images-on-mobile-email\/\">mobile email example<\/a>. We only needed to make two small tweaks to our mobile example to support rollovers on the web.<\/p>\n<p>1) First we replace the div that contains the background image with a table and set the alternate image as a table background. This is because Outlook.com does not support <a href=\"https:\/\/freshinbox.com\/blog\/outlook-com-and-background-images\/\">background-image styles<\/a>.<\/p>\n<pre class=\"lang:default mark:1,2 decode:true\">&lt;table border=0 cellpadding=0 cellspacing=0 class=\"mobi-swap-content\"\r\n  background=\"http:\/\/...\/back-image.jpg\"&gt;\r\n&lt;tr&gt;&lt;td&gt;\r\n  &lt;a href=\"http:\/\/...\/product-link\"&gt;&lt;img src=\"http:\/\/...\/front-image.jpg\" \r\n  style=\"display:block;\" height=265 width=250 alt=\"...\" border=0&gt;\r\n&lt;\/a&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;<\/pre>\n<p>2) We add a new hover rule that targets the image itself and we change the sibling CSS selector within the media query to target a table instead of a div.<\/p>\n<pre class=\"lang:default mark:1,2,3,7 decode:true\">.mobi-swap-content:hover img{\r\n  visibility: hidden;\r\n}\r\n\r\n @media screen and (max-device-width: 480px) {\r\n  ...\r\n  div[class=mobi-swap-open]:hover + table[class=mobi-swap-content] img{\r\n   visibility:hidden;\r\n  }\r\n}<\/pre>\n<h4>Final markup<\/h4>\n<p>Here&#8217;s the final markup:<\/p>\n<pre class=\"lang:default decode:true\">&lt;style&gt;\r\nbody {\r\n      -webkit-text-size-adjust:none;\r\n}\r\n.mobi-swap-content:hover img{\r\n   visibility: hidden;\r\n}\r\n\u00a0@media screen and (max-device-width: 1024px) {\r\n  div[class=mobi-swap-open], div[class=mobi-swap-close]{\r\n    display: block !important;\r\n    max-height: none !important;   \r\n    background-color: #eeeeee;\r\n    padding-left:10px;\r\n    font: 15px Helvetica;\r\n    line-height:40px;\r\n  }\r\n  div[class=mobi-swap-open] a, div[class=mobi-swap-close] a{\r\n    display:block;\r\n    text-decoration:none;\r\n  }\r\n  div[class=mobi-swap-open] {\r\n    position:absolute;\r\n    bottom:0px;\r\n    left:0px;\r\n    right:0px;\r\n  }\r\n  div[class=mobi-swap-open]:hover {\r\n    visibility: hidden;\r\n  }\r\n  div[class=mobi-swap-open]:hover + table[class=mobi-swap-content] img{\r\n    visibility:hidden;\r\n  }\r\n}\r\n&lt;\/style&gt;\r\n&lt;div style=\"position:relative;\"&gt;\r\n&lt;!--[if !mso 9]&gt;&lt;!--&gt;\r\n &lt;div class=\"mobi-swap-open\" \r\n    style=\"top:auto;bottom:0px;display:none;max-height:0px;overflow:hidden;\"&gt;\r\n  &lt;a href=\"#\"&gt;Tap here to show back&lt;\/a&gt;\r\n &lt;\/div&gt;\r\n&lt;!--&lt;![endif]--&gt;\r\n &lt;table border=0 cellpadding=0 cellspacing=0 class=\"mobi-swap-content\" \r\n    background=\"https:\/\/freshinbox.com\/examples\/tap-to-switch\/images\/back-sm.jpg\"&gt;\r\n   &lt;tr&gt;&lt;td&gt;\r\n    &lt;a href=\"http:\/\/www.amazon.com\/XOXO-Womens-Colorblocked-Dress-White\/dp\/B00GOQ1CJM\"&gt;\r\n    &lt;img src=\"https:\/\/freshinbox.com\/examples\/tap-to-switch\/images\/front-sm.jpg\" \r\n     style=\"display:block;\" height=265 width=250 alt=\"XOXO Womens Colorblocked Body Con Dress\" border=0&gt;\r\n    &lt;\/a&gt;\r\n &lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;\r\n&lt;!--[if !mso 9]&gt;&lt;!--&gt;\r\n &lt;div class=\"mobi-swap-close\" \r\n   style=\"display:none;max-height:0px;overflow:hidden;\"&gt;\r\n  &lt;a href=\"#\"&gt;Tap here to show front&lt;\/a&gt;\r\n &lt;\/div&gt;\r\n&lt;!--&lt;![endif]--&gt;\r\n&lt;\/div&gt;<\/pre>\n<style><!--\nbody {\n      -webkit-text-size-adjust:none;\n}\n.mobi-swap-content:hover img{\n   visibility: hidden;\n}\n@media screen and (max-device-width: 1024px) {\n  div[class=mobi-swap-open], div[class=mobi-swap-close]{\n    display: block !important;\n    max-height: none !important;   \n    background-color: #eeeeee;\n    padding-left:10px;\n    font: 15px Helvetica;\n    line-height:40px;\n  }\n  div[class=mobi-swap-open] a, div[class=mobi-swap-close] a{\n    display:block;\n    text-decoration:none;\n  }\n  div[class=mobi-swap-open] {\n    position:absolute;\n    bottom:0px;\n    left:0px;\n    right:0px;\n  }\n  div[class=mobi-swap-open]:hover {\n    visibility: hidden;\n  }\n  div[class=mobi-swap-open]:hover + table[class=mobi-swap-content] img{\n    visibility:hidden;\n  }\n}\n--><\/style>\n<p>&nbsp;<\/p>\n<div style=\"position: relative; width: 250px; margin: 0 auto;\"><b>Live example:<\/b><br \/>\nView on mobile to see tappable areas.&nbsp;<\/p>\n<div class=\"mobi-swap-open\" id=\"#mobi-swap-container\" style=\"top: auto; bottom: 0px; display: none; max-height: 0px; overflow: hidden;\"><a href=\"#mobi-swap-container\">Tap here to show back<\/a><\/div>\n<table class=\"mobi-swap-content\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"https:\/\/freshinbox.com\/examples\/tap-to-switch\/images\/back-sm.jpg\">\n<tbody>\n<tr>\n<td style=\"padding: 0;\"><a href=\"http:\/\/www.amazon.com\/XOXO-Womens-Colorblocked-Dress-White\/dp\/B00GOQ1CJM\"><img decoding=\"async\" loading=\"lazy\" style=\"display: block;\" alt=\"XOXO Womens Colorblocked Body Con Dress\" src=\"https:\/\/freshinbox.com\/examples\/tap-to-switch\/images\/front-sm.jpg\" width=\"250\" height=\"265\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"mobi-swap-close\" style=\"display: none; max-height: 0px; overflow: hidden;\"><a href=\"#mobi-swap-container\">Tap here to show front<\/a><\/div>\n<\/div>\n<div id=\"email-me\"><input id=\"email-me-email\" type=\"email\" placeholder=\"Email address\" \/> <input id=\"email-me-btn\" type=\"button\" value=\"Email Me This Example\" \/><\/div>\n<p>&nbsp;<\/p>\n<style><!--\n#email-me {\n  padding:10px 10px;\n  font-family: \"Lucida Grande\";\n\n}\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\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}\n#email-me-btn:hover {\n  background-color: #78D62C;\n}\n#email-me{\n  width: 400px;\n  padding:20px;\n  border:3px solid #888888;\n  border-radius: 5px;\n}\n--><\/style>\n<p>&nbsp;<\/p>\n<p><script type=\"text\/javascript\" src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.10.2\/jquery.min.js\"><\/script><br \/>\n<script>\nvar 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\/tap-to-switch\/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>In previous articles we saw how we can implement interactive image rollovers for either <a href=\"http:\/\/freshinbox.com\/blog\/3-steps-to-create-an-interactive-email-using-css\/\">webmail<\/a> or <a href=\"http:\/\/freshinbox.com\/blog\/interactive-images-on-mobile-email\/\">mobile email<\/a>.<BR><BR><\/p>\n<p>This tutorial will go over how we can combine both techniques for an image rollover example that works with mobile AND non-mobile email clients&#8230;<\/p>\n","protected":false},"author":2,"featured_media":244,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19,24,25],"tags":[8,11,10,5,16,42,9,4,14,34,39,38,40,15,41,36],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/346"}],"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=346"}],"version-history":[{"count":33,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions\/371"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/244"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}