1 | # postcss-at2x [![Build Status](https://travis-ci.org/simonsmith/postcss-at2x.svg)](https://travis-ci.org/simonsmith/postcss-at2x)
|
2 |
|
3 | Ported from [rework-plugin-at2x](https://github.com/reworkcss/rework-plugin-at2x)
|
4 |
|
5 | ## Installation
|
6 |
|
7 | ```console
|
8 | $ npm install postcss-at2x --save-dev
|
9 | ```
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ```js
|
14 | var fs = require('fs');
|
15 | var postcss = require('postcss');
|
16 | var at2x = require('postcss-at2x');
|
17 |
|
18 | var css = fs.readFileSync('input.css', 'utf8');
|
19 |
|
20 | var output = postcss()
|
21 | .use(at2x())
|
22 | .process(css)
|
23 | .css;
|
24 | ```
|
25 |
|
26 | ### .at2x()
|
27 |
|
28 | Adds `at-2x` keyword to `background` and `background-image` declarations to add retina support for images.
|
29 |
|
30 | **Input**
|
31 |
|
32 | ```css
|
33 | .logo {
|
34 | background: red url('/public/images/logo.png') no-repeat 0 0 at-2x;
|
35 | }
|
36 |
|
37 | .banner {
|
38 | background: url(/public/images/cool.png) at-2x,
|
39 | url(http://example.com/flowers-pattern.jpg) at-2x;
|
40 | }
|
41 | ```
|
42 |
|
43 | **Output**
|
44 |
|
45 | ```css
|
46 | .logo {
|
47 | background: red url('/public/images/logo.png') no-repeat 0 0;
|
48 | }
|
49 |
|
50 | .banner {
|
51 | background: url(/public/images/cool.png),
|
52 | url(http://example.com/flowers-pattern.jpg);
|
53 | }
|
54 |
|
55 | @media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
|
56 | .logo {
|
57 | background: red url('/public/images/logo@2x.png') no-repeat 0 0;
|
58 | }
|
59 | }
|
60 |
|
61 | @media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
|
62 | .banner {
|
63 | background: url(/public/images/cool@2x.png),
|
64 | url(http://example.com/flowers-pattern@2x.jpg);
|
65 | }
|
66 | }
|
67 | ```
|
68 |
|
69 | ### Options
|
70 |
|
71 | ##### `identifier` (default: `"@2x"`) _string_
|
72 |
|
73 | Change the identifier added to retina images, for example `file@2x.png` can be `file-retina.png`.
|
74 |
|
75 | ## Differences from rework-at2x
|
76 |
|
77 | * Supports multiple background images and `background` shorthand with properties. See `test/fixtures/` for examples.
|
78 |
|
79 | See [PostCSS](https://github.com/postcss/postcss/) docs for examples for your environment.
|