README
Postcss-graceful
Postcss-graceful 是一个能够帮助你更加写出更加简洁、优雅的CSS的样式解决方案。
Postcss-graceful不仅提供了下一代css语法支持,还提供了基础的sass的语法、属性顺时针简写、rem填充、基础图形声明、可定制样式的inline-svg以及bem风格类名转化等实用的功能。
Examples
顺时针简写
/* before */
a {
position: absolute 1em 2em 3em 4em;
}
a {
position: absolute 1em * * 4em;
}
/* after */
a {
top: 1em;
right: 2em;
bottom: 3em;
left: 4em;
position: absolute;
}
a {
top: 1em;
left: 4em;
position: absolute;
}
可定制的inline-svg
/* before */
@svg-load nav url(../svgs/nav.svg) {
path:nth-child(2){
fill:#0ff
};
}
h1 {
background: svg-inline(nav)
}
/* after */
h1 {
background: url("data:image/svg+xml;charset=utf-8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 50 50\'><path d=\'M10 12h30v4H10z\'/><path d=\'M10 22h30v4H10z\' fill=\'#0ff\'/><path d=\'M10 32h30v4H10z\'/></svg>");
}
基础sass语法
/* before */
$pass: green !default;
@define-placeholder foo {
background: pink;
}
.bar {
@extend foo;
background-color: @color;
color: $pass;
}
/* after */
.bar {
background: pink;
}
.bar {
background-color: green;
color: green;
}
Usage
Add Postcss graceful to your build tool:
npm install postcss-graceful --save-dev
Node
require('postcss-graceful').process(YOUR_CSS, { /* options */ });
PostCSS
Add [PostCSS] to your build tool:
npm install postcss --save-dev
Load Postcss graceful as a PostCSS plugin:
postcss([
require('postcss-graceful')({ /* options */ })
]).process(YOUR_CSS, /* options */);
Gulp
Add [Gulp PostCSS] to your build tool:
npm install gulp-postcss --save-dev
Enable Postcss graceful within your Gulpfile:
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./src/*.css').pipe(
postcss([
require('postcss-graceful')({ /* options */ })
])
).pipe(
gulp.dest('.')
);
});
options
you can change the plugin's behaviour by the options
var options = {
browser: ['ie > 8', 'last 2 version'],
features: {
"bem": false, //pass boolean false can disable the plugin
"inlineSvg": {
"path": "src/svgs"
}
}
}
Plugins
Postcss-graceful powered by the following plugins (in this order):
- precss: a tool that allows you to use Sass-like markup in your CSS files
- postcss-bem: implementing BEM as at-rules
- postcss-calc: plugin to reduce calc()
- postcss-initial: fallback initial keyword
- postcss-inline-svg: reference an SVG file and control its attributes with CSS syntax.
- postcss-short-font-size: extends the font-size property so that line-height may be set by the second value.
- postcss-short-spacing: lets you write shorthand margin and padding properties while omitting edges in CSS.
- postcss-color-function: W3C color methods
- postcss-short-size: Write shorthand size properties in CSS
- postcss-short-position: Define edges inside the position property in CSS
- postcss-graceful: draw basic graceful with specified syntax in css rule
- node-pixrem: generates pixel fallbacks for rem units.
- autoprefixer: parse CSS and add vendor prefixes to CSS rules using values from Can I Use