Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

rikki-iki/postcss-rgb-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcss-rgb-filter

PostCSS plugin to convert rgb colors to css filters.

Full credit to MultiplyByZer0 for this code. This PostCSS plugin just wraps that code.

Created to help colour SVG background images.

For this code to work well the starting color of the icon SVG needs to be black. Also note filters are not supported in IE11, so the black icon will be the fallback.

.foo {
  filter: rgb(0, 92, 250);
}

Converts to:

.foo {
  filter: invert(25%) sepia(96%) saturate(4236%) hue-rotate(214deg) brightness(97%) contrast(107%);
}

Install

npm i --save-dev postcss-rgb-filter

Usage

postcss([ require('postcss-rgb-filter') ])

See PostCSS docs for examples for your environment.

If you use the css variables plugin and want to use a variable for the color value, make sure it also runs before this plugin.

If you prefer writing colours in hex format simple add a plugin like postcss-rgb-plz and make sure it runs before this plugin.

If you use an autoprefixer plugin make sure it runs after this plugin, otherwise the prefixed value won't be converted.

About

PostCSS Plugin for converting rgb value into a CSS filter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published