@csstools/postcss-image-set-function
Deliver the most appropriate image resolution for a device using the image-set() function in CSS
Last updated 8 years ago by jonathantneal .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @csstools/postcss-image-set-function 
SYNC missed versions from official npm registry.

postcss-image-set-polyfill CSS Standard Status Build Status npm version

PostCSS plugin for polyfilling image-set CSS function.

.foo {
  align-items: center;
  background-image: image-set(url(img/test.png) 1x,
                              url(img/test-2x.png) 2x,
                              url(my-img-print.png) 600dpi);
  color: black;
}

/* becomes */

.foo {
  align-items: center;
  background-image: url(img/test.png);
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .foo {
    background-image: url(img/test-2x.png);
  }
}

@media (-webkit-min-device-pixel-ratio: 6.25), (min-resolution: 600dpi) {
  .foo {
    background-image: url(my-img-print.png);
  }
}

.foo {
  color: black;
}

→Try it online←

❗️ Resolution media query is supported only by IE9+.

Installation

npm i postcss-image-set-polyfill -D

Usage

var postcssImageSet = require('postcss-image-set-polyfill');

postcss([postcssImageSet]).process(YOUR_CSS, /* options */);

See PostCSS docs for examples for your environment.

Option

preserve

The preserve option determines whether the original image-set() rule should or not should not be removed. By default, the original image-set() rule is removed.

postcssImageSet({ preserve: true })
.foo {
  align-items: center;
  background-image: image-set(url(img/test.png) 1x,
                              url(img/test-2x.png) 2x);
  color: black;
}

/* becomes */

.foo {
  align-items: center;
  background-image: url(img/test.png);
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .foo {
    background-image: url(img/test-2x.png);
  }
}

.foo {
  background-image: image-set(url(img/test.png) 1x,
                              url(img/test-2x.png) 2x);
  color: black;
}

⚠️️ Warning

If you use autoprefixer, place this plugin before it to prevent styles duplication.

Current Tags

  • 1.0.0                                ...           latest (8 years ago)

1 Versions

  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (2)
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |