Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
postcss-custom-media
Advanced tools
PostCSS plugin to transform W3C CSS Custom Media Queries to more compatible CSS
The postcss-custom-media package allows you to define custom media queries in CSS, which can then be reused throughout your stylesheets. This helps in maintaining a consistent and DRY (Don't Repeat Yourself) approach to media queries.
Define Custom Media Queries
This feature allows you to define custom media queries using the @custom-media rule. In this example, a custom media query named --small-viewport is defined for viewports with a maximum width of 30em.
@custom-media --small-viewport (max-width: 30em);
Use Custom Media Queries
Once a custom media query is defined, it can be used in your CSS just like any other media query. In this example, the custom media query --small-viewport is used to change the text color to red for small viewports.
body { color: black; }
@media (--small-viewport) { body { color: red; } }
postcss-preset-env allows you to use future CSS features today by converting modern CSS into something most browsers can understand. It includes a variety of plugins, including the ability to use custom media queries. Compared to postcss-custom-media, postcss-preset-env offers a broader range of features but may be overkill if you only need custom media queries.
postcss-media-minmax lets you write simpler and more concise media queries by using the < and > operators. While it doesn't offer custom media queries, it simplifies the syntax of media queries, making them easier to read and write. It is a good alternative if you are looking for a way to simplify your media queries without defining custom ones.
PostCSS plugin to transform W3C CSS Custom Media Queries syntax to more compatible CSS.
$ npm install postcss-custom-media
// dependencies
var postcss = require("postcss")
var customMedia = require("postcss-custom-media")
// css to be processed
var css = fs.readFileSync("input.css", "utf8")
// process css using postcss-custom-media
var out = postcss()
.use(customMedia())
.process(css)
.css
Using this input.css
:
@custom-media --small-viewport (max-width: 30em);
@media (--small-viewport) {
/* styles for small viewport */
}
you will get:
@media (max-width: 30em) {
/* styles for small viewport */
}
Checkout tests for more examples.
extensions
(default: {}
)Allows you to pass an object to define the <media-query-list>
for each <extension-name>
. These definitions will override any that exist in the CSS.
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
$ git clone https://github.com/postcss/postcss-custom-media.git
$ git checkout -b patch-1
$ npm install
$ npm test
FAQs
Use Custom Media Queries in CSS
The npm package postcss-custom-media receives a total of 1,082,084 weekly downloads. As such, postcss-custom-media popularity was classified as popular.
We found that postcss-custom-media demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.