{"id":792,"date":"2014-08-11T18:58:59","date_gmt":"2014-08-11T18:58:59","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=792"},"modified":"2014-08-13T09:17:36","modified_gmt":"2014-08-13T09:17:36","slug":"gmail-supports-style-sort-of","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/gmail-supports-style-sort-of\/","title":{"rendered":"Gmail supports the Style tag!\u2026 Well sort of"},"content":{"rendered":"<p><b>Update:<\/b> Here&#8217;s an article that goes into a bit more detail: <a href=\"https:\/\/freshinbox.com\/blog\/interactive-emails-in-gmail-using-css-attribute-selectors\/\" title=\"Make your email interactive in Gmail by using CSS attribute selectors\">Make your email interactive in Gmail by using CSS attribute selectors<\/a>.<\/p>\n<p>Will you be surprised to hear you can actually put CSS including pseudo-classes like :hover in a &lt;style&gt; block and have them work in Gmail? Well as I found out recently, you can! <\/p>\n<p>Before we start, I want to make it clear we\u2019re talking about the Gmail webmail client and not the Gmail mobile apps &#8211; which sadly still lack any support for the &lt;style&gt; tag.<\/p>\n<p>Email designers have always complained that Gmail\u2019s lack of support for embedded styles (CSS within the &lt;style&gt; tag) has forced them to &#8220;inline&#8221; CSS in order for emails to look great in Gmail. Since pseudo-classes such as :hover cannot be inlined, it is believed that Gmail cannot be made to display interactive goodies such as <a href=\"https:\/\/freshinbox.com\/blog\/3-steps-to-create-an-interactive-email-using-css\/\">Rollover Images<\/a>. Hence, the <a href=\"https:\/\/freshinbox.com\/blog\/gmail-can-has-style\/\">@Gmail #CanHasStyle campaign<\/a> earlier this year to push for wider embedded CSS support within Gmail.<\/p>\n<p><strong>Gmail Webmail #HasStyle?<\/strong><\/p>\n<p>Earlier this year the folks at Email on Acid <a href=\"https:\/\/www.emailonacid.com\/blog\/details\/C13\/gmail_web_app_allows_style\">noticed<\/a> that Gmail actually allows the &lt;style&gt; tag in the head. The problem was that Gmail strips elements of class and id attributes. So even if your embedded styles contain id and class selectors (#id and .class), it would not match any elements in the body of the email. <\/p>\n<p>However, after a fair bit of sleuthing I\u2019ve found out that there is a method to simulate class attributes and that is by using other attributes that Gmail does not strip &#8211; one of which is the title <a href=\"http:\/\/www.w3schools.com\/tags\/ref_standardattributes.asp\">attribute<\/a>.<\/p>\n<p>In addition, I also discovered that although Gmail is very strict on single selectors, it is surprisingly lenient on descendent selectors. And just by adding a universal (*) selector before your style, you can get around the strict restrictions.<\/p>\n<p>This markup will display a hoverable box that changes color in Gmail:<\/p>\n<pre class=\"lang:default decode:true \" >&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;style&gt;\r\n* [title=\"divbox\"]:hover{\r\n  background-color: green !important;\r\n  color: white;\r\n}\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div title=\"divbox\" style=\"padding:10px;width:100px;height:40px;\r\n  background-color:#eeeeee;\"&gt;Divbox Content&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><BR><br \/>\n<img decoding=\"async\" src=\"https:\/\/freshinbox.com\/blog\/wp-content\/uploads\/2014\/08\/gmail-hover.gif\" alt=\"gmail-hover\" width=\"450\" class=\"aligncenter\" \/><BR><BR><\/p>\n<p>I\u2019m still exploring this rabbit hole so stay tuned for more\u2026 :)<BR><BR><\/p>\n<p><em><strong>PS: <\/strong>Gmail, if you&#8217;re reading this, I\u2019d like to say that this technique is not meant as sneaky exploit but as a means to allow us designers to do what we&#8217;ve always been able to do with other email clients &#8211; yes, including that notorious Microsoft desktop client that is dead to us #WhatIsDeadMayNeverDie.  So if you decide to patch this &#8220;feature&#8221;, I\u2019d implore you to at least give us class attributes\u2026 and perhaps consider adding that support to the Gmail mobile apps as well!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Will you be surprised to hear you can actually put CSS including pseudo-classes like :hover in a &lt;style&gt; block and have them work in Gmail? Well as I found out recently, you can! &#8230;<\/p>\n","protected":false},"author":2,"featured_media":821,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,19,28,24],"tags":[],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/792"}],"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=792"}],"version-history":[{"count":33,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/792\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/792\/revisions\/878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/821"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}