tijsverkoyen / CssToInlineStyles

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.
BSD 3-Clause "New" or "Revised" License
5.8k stars 187 forks source link

Ensure correct ordering of styles #159

Closed Stadly closed 8 years ago

Stadly commented 8 years ago

When a property can be set using different names, such as padding and padding-left, the inlined styles were not always correctly ordered.

Examples:

<style type="text/css">
span.test {
   background-color: blue;
}
span {
   background: red;
}
</style>
<span class="test">This should be blue</span>

Will result in <span style="background-color: blue; background: red;">This should be blue</span> even though background-color: blue; has higher specificity than background: red;. This issue is fixed by sorting all rules by specificity instead of order of appearance: https://github.com/tijsverkoyen/CssToInlineStyles/commit/bdf1c2e623ccfcf4de2d6d30264687632715228d

<style type="text/css">
span {
   background: red;
}
</style>
<span style="background-color: blue;">This should be blue</span>

Will result in <span style="background-color: blue; background: red;">This should be blue</span> since the styles being inlined are positioned after the styles that were already inline. This issue is fixed by positioning the styles that were already inline last: https://github.com/tijsverkoyen/CssToInlineStyles/commit/716da4a48b2d76b05c4069e41fd03433e39c3633, https://github.com/tijsverkoyen/CssToInlineStyles/commit/e7d45286a41bd43ae6acba96e9c5412218c8c6e3

stof commented 8 years ago

isn't this a duplicate of #155 ?

Stadly commented 8 years ago

Yes. How did I overlook that? 👎 It seems that https://github.com/tijsverkoyen/CssToInlineStyles/pull/155 fixes the first issue, while the second issue where inline styles are not put last is not fixed by that PR.

Hikariii commented 8 years ago

Improved this and made https://github.com/tijsverkoyen/CssToInlineStyles/pull/160.

tijsverkoyen commented 8 years ago

Fixed in #160