CssToInlineStyles class
CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails.
Grab your copy
About
PHP CssToInlineStyles is a class to convert HTML into HTML with inline styles.
License
CssToInlineStyles is BSD licensed.
Documentation
The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc.
Sites that use this class
Do you know a site that uses this class? Use the form below.
Comments
Add your comment
If you have some feedback, a remark or you just want to say something. Go ahead, use the form below.
Tijs Verkoyen wrote:
15/05/2010
Changelog since 1.0.1
- fixed some stuff on specifity
Changelog since 1.0.0
- rewrote the buildXPathQuery-method
- fixed some stuff on specifity
- added a way to use inline style-blocks
lmeurs wrote:
08/07/2010
Hey Thijs,
Great script you developed, thanks a lot for that!
One question: if one defines general styles for some headings like ie. h1,h2,h3 {...} and later on a specific style for a heading like ie. h1 {...}, the latter addes styles are ignored.
I'm fairy new to PHP and tried to solve it in the sortOnSpecifity function, but unfortunately I did not succeed.
Not a big bug, but a bug! :-)
Thanks again, cheers!
Laurens (Rotterdam)
Jeremy Shipman wrote:
15/07/2010
Hi Tijs, thanks for sharing your code with the world.
I'm getting a strange bug where
<p>
Jeremy Shipman wrote:
15/07/2010
...seems my comment didn't come out fully.
I'm getting an bug where paragraphs containing only a non breaking space character suddenly also have another character in them:
Jeremy Shipman wrote:
15/07/2010
Hello again Tijs, I've found the problem... it was to do with the character encoding using the utf8_decode fixed it.
Peter wrote:
20/07/2010
Hey there Tijs.
Thanks for the great script! Question though:
In my HTML I have...
<div class="something">...</div>
...but CssToInlineStyles ignores the class as written in my stylesheet...
.something {
font-size: 11px;
line-height: 13px;
}
Why is the above class ignored as written? The class DOES get applied however if written like this...
div.something {
font-size: 11px;
line-height: 13px;
}
Which is fine unless it's a class that I'd like to apply to many things such as div, p, td, span, etc.
Is there any way to have a class applied without having to precede it with a specific tag in the stylesheet?
Thank you kindly!
Peter
Peter wrote:
20/07/2010
Does the problem I mentioned above maybe result from specificity? The div I mentioned above is wrapped in another div also like so...
<div #content>
<div class="something">...</div>
</div>
In my stylesheet, the #content selector also has font-size and line-height set. Is #content overriding .something? In the code above, I would think that .something should override #content... no?
Actually, I can't seem to apply any classes. Well, unless they are preceded by an html tag in the stylesheet like so div.something or span.something.
I'm guessing the container div with #content is overriding all the classes inside of it... which is not what happens in my web pages. Just to be sure, I tried changing the selector in my stylesheet from ".something" to "#content .something" but the class still isn't being applied. Any idea how to apply classes properly?
Thanks again!
Peter
Tijs Verkoyen wrote:
27/08/2010
Changelog since 1.0.2
- .class are matched from now on.
- fixed issue with #id
- new beta-feature: added a way to output valid XHTML (thx to Matt Hornsby)