0

I'd like to compile css and replace the resulting styles for each tag as an inline style for the corresponding tags in html. Is there a simple way to do this in c#?

This is similar to "Compile" CSS into HTML as inline styles - but I want to do it in c#

Community
  • 1
  • 1
Ryan
  • 3,924
  • 6
  • 46
  • 69

1 Answers1

4

You can use https://github.com/milkshakesoftware/PreMailer.Net

 string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");

 var result = PreMailer.MoveCssInline(htmlSource);

 result.Html         // Resultant HTML, with CSS in-lined.
 result.Warnings     // string[] of any warnings that occurred during processing.
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116