Search code examples
cssasp.net-mvc-3stylesheetstylesinline-styles

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 can get all the style in a style node.


Solution

  • 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.