6

I found this awesome class that converts CSS style blocks to inline. However, I think it has a problem. For example, if you have the following:

<style type="text/css">
.myclass{
padding:0px;
}
<style>

<p class="myclass" style="padding-top: 40px;">Test</p>

It will convert the above to:

<p class="myclass" style="padding-top: 40px; padding:0px;">Test</p>

But the above is incorrect. It should prepend since the padding-top inline has priority as it is already inline. So it should be:

<p class="myclass" style="padding:0px; padding-top: 40px;">Test</p>

But I am struggling where to make this edit in the class. I thought it would be straightforward and I could submit it to the class creator but I am struggling.

Any ideas?

7
  • Why would anyone want to have inline styles??? Commented Aug 14, 2011 at 15:24
  • @Gordon for newsletter purposes or in-place content editing, for example. Commented Aug 14, 2011 at 15:25
  • 2
    @Gordon - many email clients, ignore style blocks including Gmail. Commented Aug 14, 2011 at 15:28
  • fair enough but thats about the only two things I can think of and at least the newsletter is due to poor standards in that field only. Might want to add that it's for a newsletter then though. Commented Aug 14, 2011 at 15:29
  • If this is about emails.. then i suggest you try this: premailer.dialect.ca Commented Aug 14, 2011 at 15:33

3 Answers 3

4

The best solution is create an issue and get in touch with the developer. So he can fix it for others too. That's a growth of the community .

Just going through the code in a quick way what I think is before building the chunks reverse the array $properties

$properties = array_reverse ( $properties, true );
// build chunks
foreach($properties as $key => $values)

The $properties = array_reverse ( $properties, true ) which preserves the key on the top of build chunks on line 318 as linked will reverse all.

Hope that helps! Not sure whether this will bring any other issues, just try.

Sign up to request clarification or add additional context in comments.

3 Comments

it looks like it works with your change! Wow that is awesome! Going to test it some more.
Yes, it works for me! I found another issue with this class but I'll try solving it myself, if I can't I'll open another question. Thanks Hari! :)
Just so that everyone knows. The class has been updated by the owner and it can be found here: github.com/tijsverkoyen/CssToInlineStyles
0

in my opinion

<p class="myclass" style="padding-top: 40px; padding:0px;">Test</p>

isn't wrong. because a inline-style overwrite a class-style

2 Comments

The above will equate to the p tag having a padding of 0px -which isn't the case. It should have a padding-top of 40px.
what i mean is: if u add a class to a p-tag that have already a inlinestyle. the inlinestyle still overwrites the class. the behavior is normal.
0

Should be fixed in the latest version: see https://github.com/tijsverkoyen/CssToInlineStyles

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.