Apparently email clients strip out style tags (stylesheets) if included
in pretty, HTML emails. This is painful for any email template designer
as that means to ensure that the actual design is maintained, the CSS
styles have to be written inline.
Ouch!
The ideal scenario would be:
After seeing what MailChimp was offering, I figured maybe I could do the same thing using Javascript and jQuery, and open it up.
Conceptually, it's pretty straight forward.
First, you want to create a new document 'styleSheet' object. Using native Javascript, you can construct the new stylessheet using: document.createElement('style').
Place the styles desired to be applied, into the created stylesheet and append it to <head>. Once appended, loop through all the cssRules from the stylesheet and get the 'selectorText' field as part of the native cssRule object.
This selector text can be applied to what jQuery is notorious for thanks to Sizzle, as a selector expression. Passing this selector text into the jQuery object, will return an array of the various different dom elements to have the styles applied to.
Once the array of elements to be modified are returned, put the styles into an 'Object' so that it can then be applied to the array of elements by using the handy jQuery css method, jQuery.css({prop:value, _prop:_value}); Once applied, the styles will appear inline.
Grab the inline HTML and then return it to the user by injecting it into some sort of div.
Copy and paste your CSS snippet into this textarea Don't include the <style> tags. Just paste the CSS .
Copy and paste your HTML snippet that you want to apply the inline styles to. Don't include the <body> tag
Here you go. Below is your HTML with inline styles.
Nirvana Tikku, Tikku.com © 2010-2012