简体   繁体   中英

Make css styles inline into html elements

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#

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM