{"id":21,"date":"2013-12-19T00:45:40","date_gmt":"2013-12-19T00:45:40","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=21"},"modified":"2015-12-21T02:59:00","modified_gmt":"2015-12-21T02:59:00","slug":"3-steps-to-create-an-interactive-email-using-css","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/3-steps-to-create-an-interactive-email-using-css\/","title":{"rendered":"3 Steps to Create an Interactive Email Using CSS"},"content":{"rendered":"<p><strong>Update:\u00a0<\/strong>Here&#8217;s a tool to create this example: <a title=\"Rollover Image Builder for Email\" href=\"https:\/\/freshinbox.com\/tools\/rollover\/\">Rollover Image Builder for Email<\/a>.<\/p>\n<p>Do you find yourself trying to find new ways to engage your email audience with compelling and eye-catching content?<\/p>\n<p>This example will show you, in three easy steps, how to do just that. By creating an email that will display an alternate view upon the mouseover of an image, users will have a much more interactive and enjoyable experience.<\/p>\n<div style=\"width: 240px; margin: 30px auto;\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2013\/12\/shoe-hover-anim.gif\" width=\"240\" height=\"170\" \/><\/div>\n<h2>1. Table + Background Image<\/h2>\n<p>The first step is to create a table containing a single cell with the alternate image as the cell&#8217;s background.<\/p>\n<pre class=\"lang:default decode:true\">&lt;table cellpadding=0 cellspacing=0 border=0&gt;&lt;tr&gt;\r\n&lt;td width=240 background=\"http:\/\/...\/alternate-image.jpg\"&gt;\r\n&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>2. Link + Image<\/h2>\n<p>The next step involves adding the primary image wrapped within a link. Add the class &#8220;img-swap&#8221; to the link and set the style &#8220;display:block;&#8221; to the image.<\/p>\n<pre class=\"wrap:true lang:default mark:3 decode:true\">&lt;table cellpadding=0 cellspacing=0 border=0&gt;&lt;tr&gt;\r\n&lt;td width=240 background=\"http:\/\/..\/alternate-image.jpg\"&gt;\r\n&lt;a class=\"img-swap\" href=\"http:\/\/..\/link\"&gt;&lt;img src=\"http:\/\/..\/primary-image.jpg\" width=\"240\" height=\"170\" border=\"0\" style=\"display:block;\" alt=\"the product\"&gt;&lt;\/a&gt;\r\n&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>3. Style + Hover<\/h2>\n<p>The third and final step is adding styles to the link and setting the :hover pseudo-class on the link that targets the image within it. By setting the height of the image to 0px when the cursor is over the link, the image is hidden and the background image of the table cell is displayed. The link&#8217;s display style is set to &#8220;block&#8221; so that the link retains its width and height even when the enclosed image is collapsed allowing the user to click on it.<\/p>\n<p><strong>Update:\u00a0<\/strong>This article covers a neat trick to get this to <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\">work in Gmail webmail<\/a>.<\/p>\n<pre class=\"lang:default decode:true\">&lt;style&gt;\r\n.img-swap {\r\n  display: block;\r\n  width: 240px;\r\n  height: 170px;\r\n}\r\n\r\n.img-swap:hover img {\r\n  height: 0px;\r\n}\r\n&lt;\/style&gt;<\/pre>\n<style><!--\n.img-swap {\n  display: block;\n  width: 240px;\n  height: 170px;\n}\n.img-swap:hover img {\n  height: 0px;\n}\n--><\/style>\n<div style=\"width: 255px; margin: 30px auto; text-align: center;\">\n<div style=\"width: 245px; border: 4px solid #dddddd;\">\n<table style=\"border: 0px; border-color: #ffffff;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"padding: 0px;\" width=\"240\" background=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2013\/12\/shoe_b.jpg\"><a class=\"img-swap\" href=\"http:\/\/store.nike.com\/us\/en_us\/pd\/free-flyknit-running-shoe\/pid-726162\/pgid-1058624\"><img decoding=\"async\" loading=\"lazy\" style=\"display: block;\" alt=\"Nike Free Flyknit+\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2013\/12\/shoe_a.jpg\" width=\"240\" height=\"170\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Mouseover the image above<\/p>\n<\/div>\n<p>See how it works in your inbox by sending yourself an <a title=\"Interactive Email Example\" href=\"https:\/\/freshinbox.com\/tools\/rollover\/\">example<\/a>.<\/p>\n<h2>Client support<\/h2>\n<p>The effects will be visible for users on Yahoo! Mail, Outlook.com (aka Hotmail), AOL as well as Outlook 2003. Clients that don&#8217;t support embedded style tags such as Gmail will just not respond to the hover event. Although the interactive effect does not work on Outlook 2007 and above, they still render perfectly, which is a huge plus! A coming article will focus on how to leverage the same techniques for mobile clients.<\/p>\n<p>I&#8217;m interested to see how others are using the :hover pseudo-class or any other method to create interactive content in email. Let me know in the comments or on Twitter if this is something you find interesting or are considering trying out!<\/p>\n<p><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","protected":false},"excerpt":{"rendered":"<p>Do you find yourself trying to find new ways to engage your email audience with compelling and eye-catching content?<BR><BR><\/p>\n<p>This example will show you, in three easy steps, how to do just that. By creating an email that will display an alternate view of a product when the recipient hovers the cursor over an image, users will have a much more interactive and enjoyable experience&#8230;<\/p>\n","protected":false},"author":2,"featured_media":57,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,25],"tags":[8,3,11,10,5,16,9,4,14,15,13],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/21"}],"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=21"}],"version-history":[{"count":40,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":2489,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions\/2489"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/57"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}