Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
postcss-custom-properties-fallback
Advanced tools
This plugins adds fallbacks to your CSS Custom Properties and works well as a compantion to PostCSS Custom Properties.
If we remove --color
from :root
, what color will h1
have in modern browsers?
:root {
- --color: red;
}
body {
color: green;
}
h1 {
color: red;
color: var(--color);
}
h1
is red
Nope, it's green
!
Intuitively it's easy to think that if --color
isn't defined, then the browser should skip the color: var(--color)
and use the valid color: red
above it.
Especially since this is what happens in older browsers that don't support CSS Custom Properties.
The right answer is to use the second argument in var()
(see Example 10 in the spec), also known as the fallback argument:
color: var(--color, red);
Now it works like expected. See the spec for more information on how invalid/missing values are treated.
h1
is green
Right answer! Check the wrong answer to learn why that is.
Add PostCSS Custom Properties Fallback to your project:
npm install postcss-custom-properties-fallback --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssCustomPropertiesFallback = require('postcss-custom-properties-fallback');
postcss([postcssCustomPropertiesFallback(/* pluginOptions */)]).process(
YOUR_CSS /*, processOptions */
);
The importFrom
option is required. It works like from CSS Custom Properties, except it doesn't support importing from CSS yet.
postcssCustomPropertiesFallback({
importFrom: { customProperties: { '--color': 'red' } },
});
h1 {
color: var(--color);
}
/* becomes */
h1 {
color: var(--color, red);
}
FAQs
Adds fallbacks to your CSS var() functions
The npm package postcss-custom-properties-fallback receives a total of 3,222 weekly downloads. As such, postcss-custom-properties-fallback popularity was classified as popular.
We found that postcss-custom-properties-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.