开发者

ASP.NET MVC Inline Styling convert

Is there anyway I can get the all style of a page (even the style in some linked css files) as inline style?

For example, I have my css file:

body {
    background-color: red;
    color: black;
}

And this HTML:

<html>
    <head>
        <link href="styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>Hello World!</body>
</html>

So I'd like to get:

<html>
    <head></head>
    <body style="background-color: red; color: black;">Hello World!</body>
</html>

It would also work for me if I 开发者_StackOverflow社区can get all the style in a style node.


from your comments, what you need is very different

What you are looking for is a tool that grabs an HTML page with it's own CSS styling and convert them into inline styling.

For that, plenty of tools are at your service:

http://premailer.dialect.ca/

There are more in Google, this is commonly used in Mailing as Email Client Applications do not intrepertate linked CSS but inline css.


If you are looking for a .NET solution, you might be interested in PreMailer.NET.

https://github.com/milkshakesoftware/PreMailer.Net

PreMailer pm = new PreMailer();
string premailedOutput = pm.MoveCssInline(htmlSource, false);


Old post, but I finally (2 years late!) got this up on github and in nuget:

https://github.com/lukeschafer/HtmlCleanser

Note: Premailer.Net (suggested by Arical) does not inline correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜