https://github.com/csstools/postcss-unroot
Swap :root with html in CSS selectors
https://github.com/csstools/postcss-unroot
Last synced: 11 months ago
JSON representation
Swap :root with html in CSS selectors
- Host: GitHub
- URL: https://github.com/csstools/postcss-unroot
- Owner: csstools
- License: other
- Created: 2015-10-04T19:34:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-12-09T16:57:29.000Z (over 4 years ago)
- Last Synced: 2024-05-27T12:43:38.227Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 2
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# UnRoot [![Build Status][ci-img]][ci]

[UnRoot] replaces selectors containing `:root` with `html`. This can be useful for outputting CSS for older browsers like Internet Explorer 8.
```css
/* before */
:root {
background-color: black;
color: white;
}
/* after */
html {
background-color: black;
color: white;
}
```
## Usage
Follow these steps to use [UnRoot].
Add [UnRoot] to your build tool:
```bash
npm install postcss-unroot --save-dev
```
#### Node
```js
require('postcss-unroot')({ /* options */ }).process(YOUR_CSS);
```
#### PostCSS
Add [PostCSS] to your build tool:
```bash
npm install postcss --save-dev
```
Load [UnRoot] as a PostCSS plugin:
```js
postcss([
require('postcss-unroot')({ /* options */ })
]);
```
#### Gulp
Add [Gulp PostCSS] to your build tool:
```bash
npm install gulp-postcss --save-dev
```
Enable [UnRoot] within your Gulpfile:
```js
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('postcss-unroot')({ /* options */ })
])
).pipe(
gulp.dest('./css')
);
});
```
#### Grunt
Add [Grunt PostCSS] to your build tool:
```bash
npm install grunt-postcss --save-dev
```
Enable [UnRoot] within your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-unroot')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});
```
### Options
#### `method`
Type: `String`
Default: `'replace'`
##### `replace`
Replace any selectors with `:root` with `html`.
```css
/* before */
:root {
color: red;
}
/* after */
html {
color: red;
}
```
##### `copy`
Copy any selectors with `:root` into a cloned rule as `html`.
```css
/* before */
:root {
color: red;
}
/* after */
html {
color: red;
}
:root {
color: red;
}
```
##### `warn`
Warn when a `:root` selector is used.
[ci]: https://travis-ci.org/jonathantneal/postcss-unroot
[ci-img]: https://travis-ci.org/jonathantneal/postcss-unroot.svg
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[UnRoot]: https://github.com/jonathantneal/postcss-unroot