inline-css icon indicating copy to clipboard operation
inline-css copied to clipboard

Unclear if media queries should be preserved when they're in a css-file

Open seriema opened this issue 10 years ago • 8 comments
trafficstars

This issue originally started in gulp-inline-css.

I've played around with the tests in the project and if I change media-preserve.html to use <link rel="stylesheet" href="media-preserve.css" /> and move the CSS to that file then no CSS is included in the test output. If I try to add some media-query CSS to any other test that already uses external CSS files as part of the test, like in.html/file.css, and set the preserveMediaQueries: true option, I get the same result: no media query CSS is preserved.

To double check I added some media queries CSS as <style> in the HTML file I originally had issues with then those media queries are preserved, but the ones in my CSS file are ignored. Maybe this is by design? It's not super clear from the documentation although reading it now I can imagine it's technically correct. But since the main use case is Useful for emails according to the readme and it already supports applyLinkTags by default, so I assumed it would be preserved since that's the only way to make media queries work in emails.

seriema avatar Oct 07 '15 07:10 seriema

Interesting that it works in the style tag but not the link tag. I don't know that this is broken so I'll add it as a feature request.

jonkemp avatar Oct 07 '15 14:10 jonkemp

When using responsive email frameworks like zurb, where media queries are in .css file, this is very essential feature. Thanks. +1

darklow avatar Oct 10 '15 01:10 darklow

Same for me. Essential +1.

flakessp avatar Nov 19 '15 13:11 flakessp

workaround for now is to inline your whole compiled css in your template

theoephraim avatar Nov 19 '15 14:11 theoephraim

+1

simboonlong avatar Jan 12 '16 08:01 simboonlong

Any movement on this?

gavmck avatar Dec 12 '16 16:12 gavmck

+1 I also just ran into this, it's a weird and a bit disruptive for the build process we're using (not major, thankfully).

NiekHoekstra avatar Jan 02 '17 16:01 NiekHoekstra

+1 I'm also for this, but. This is pretty easy to solve if you use Gulp:

gulp.task("inject", () =>
  gulp
    .src(["./dist/**/*.html"])
    .pipe(
      replace('<style type="text/css"></style>', () => {
        const css = fs.readFileSync("dist/css/bundle.css", "utf8");

        return `<style type="text/css">\n${css}\n</style>`;
      })
    )
    .pipe(gulp.dest("./dist"))
);

Using gulp-replace, we insert styles from our external CSS file into the style tag. And then we launch inline-css. In this case, the media-css remains using the preserveMediaQueries property.

alexandr-kazakov avatar Jul 22 '20 14:07 alexandr-kazakov