
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
postcss-at2x
Advanced tools
Adds at-2x keyword to background and background-image declarations to add retina support for images.
Ported from rework-plugin-at2x
$ npm install postcss-at2x --save-dev
const fs = require('fs');
const postcss = require('postcss');
const at2x = require('postcss-at2x');
const input = fs.readFileSync('input.css', 'utf8');
const output = postcss()
.use(at2x())
.process(input)
.then(result => console.log(result.css));
Adds at-2x
keyword to background
and background-image
declarations to add retina support for images.
Input
.logo {
background: red url('/public/images/logo.png') no-repeat 0 0 at-2x;
}
.banner {
background: url(/public/images/cool.png) at-2x,
url(http://example.com/flowers-pattern.jpg) at-2x;
}
Output
.logo {
background: red url('/public/images/logo.png') no-repeat 0 0;
}
.banner {
background: url(/public/images/cool.png),
url(http://example.com/flowers-pattern.jpg);
}
@media (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
.logo {
background: red url('/public/images/logo@2x.png') no-repeat 0 0;
}
}
@media (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
.banner {
background: url(/public/images/cool@2x.png),
url(http://example.com/flowers-pattern@2x.jpg);
}
}
identifier
(default: "@2x"
) stringChange the identifier added to retina images, for example file@2x.png
can be file-retina.png
.
detectImageSize
(default: false
) booleanObtains the image dimensions of the non-retina image automatically and applies them to the
background-size
property of the retina image.
skipMissingRetina
(default: false
) booleanIf the retina image cannot be found on the file system it will be skipped and not output into the result CSS.
resolveImagePath
functionGet resolved image path for detecting image size. By default, original url
value is resolved from current working directory (process.cwd()
).
Function receives two arguments: original url
value and PostCSS declaration source.
Output
.element {
background: url(img.jpg) no-repeat;
}
@media (min-device-pixel-ratio: 1.5), (min-resolution: 144dpi), (min-resolution: 1.5dppx) {
.element {
background: url(img@2x.jpg) no-repeat;
background-size: 540px 675px; /* Dimensions of img.jpg */
}
}
background
shorthand with properties. See test/fixtures/
for examples.See PostCSS docs for examples for your environment.
FAQs
Adds at-2x keyword to background and background-image declarations to add retina support for images.
We found that postcss-at2x demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.