Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@csstools/postcss-relative-color-syntax
Advanced tools
@csstools/postcss-relative-color-syntax is a PostCSS plugin that allows you to use relative color syntax in your CSS. This can simplify color manipulations and make your stylesheets more maintainable by enabling relative color adjustments directly in your CSS.
Relative Color Syntax
This feature allows you to use relative color syntax to mix colors directly in your CSS. The example shows how to mix white and black to get a gray background color.
/* Input CSS */
body {
background-color: color-mix(in srgb, white 50%, black);
}
/* Output CSS */
body {
background-color: #808080;
}
Color Adjustments
This feature allows you to adjust colors based on contrast. The example shows how to set a button's background color to blue while ensuring it contrasts well with both white and black.
/* Input CSS */
button {
background-color: color-contrast(white vs black, blue);
}
/* Output CSS */
button {
background-color: #0000ff;
}
postcss-color-function is a PostCSS plugin that allows you to use color functions like color() in your CSS. It provides similar functionality to @csstools/postcss-relative-color-syntax but focuses more on the color() function and its capabilities.
postcss-preset-env is a PostCSS plugin that allows you to use future CSS features today. It includes a variety of plugins, including those for color manipulation, making it a more comprehensive solution compared to @csstools/postcss-relative-color-syntax.
npm install @csstools/postcss-relative-color-syntax --save-dev
PostCSS Relative Color Syntax lets you use the relative color syntax in CSS color functions following CSS Color Module 5.
.example {
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
/* becomes */
.example {
background: rgb(12, 100, 100);
}
[!NOTE] We can not dynamically resolve
var()
arguments in relative color syntax, only static values will work.
Add PostCSS Relative Color Syntax to your project:
npm install postcss @csstools/postcss-relative-color-syntax --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssRelativeColorSyntax = require('@csstools/postcss-relative-color-syntax');
postcss([
postcssRelativeColorSyntax(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
PostCSS Relative Color Syntax runs in all Node environments, with special instructions for:
The preserve
option determines whether the original notation
is preserved. By default, it is not preserved.
postcssRelativeColorSyntax({ preserve: true })
.example {
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
/* becomes */
.example {
background: rgb(12, 100, 100);
background: oklab(from oklab(54.3% -22.5% -5%) calc(1.0 - l) calc(a * 0.8) b);
}
FAQs
Use the relative color syntax in CSS
The npm package @csstools/postcss-relative-color-syntax receives a total of 841,638 weekly downloads. As such, @csstools/postcss-relative-color-syntax popularity was classified as popular.
We found that @csstools/postcss-relative-color-syntax demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.