Space Start Attributes targets attributes beginning with a certain value in a space separated list in CSS.
/* before */
div[data-thing~^"starts-with"] {
background-color: red;
}
div:not([data-thing~^"starts-with"]) {
background-color: blue;
}
/* after */
div[class^="starts-with"],div[class*=" starts-with"] {
background-color: red;
}
div:not([class^="starts-with"],[class*=" starts-with"]) {
background-color: blue;
}
Note: The above example generates a W3C CSS level 4 :not()
selector. I recommend using Selector Not to transpile this to a more compatible CSS level 3 selector.
Add Space Start Attributes to your build tool:
npm install postcss-space-start-attrs --save-dev
require('postcss-space-start-attrs').process(YOUR_CSS, { /* options */ });
Add PostCSS to your build tool:
npm install postcss --save-dev
Load Space Start Attributes as a PostCSS plugin:
postcss([
require('postcss-space-start-attrs')({ /* options */ })
]).process(YOUR_CSS, /* options */);
Add Gulp PostCSS to your build tool:
npm install gulp-postcss --save-dev
Enable Space Start Attributes within your Gulpfile:
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./src/*.css').pipe(
postcss([
require('postcss-space-start-attrs')({ /* options */ })
])
).pipe(
gulp.dest('.')
);
});
Add Grunt PostCSS to your build tool:
npm install grunt-postcss --save-dev
Enable Space Start Attributes within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
use: [
require('postcss-space-start-attrs')({ /* options */ })
]
},
dist: {
src: '*.css'
}
}
});