Time Machine fixes mistakes in the design of CSS itself, as described by the CSSWG.
They specifically requested that these should be corrected “if anyone invents a time machine”.
no-wrap
In
white-space,nowrapshould be calledno-wrap.
/* before */
h1 {
white-space: no-wrap;
}
/* after */
h1 {
white-space: nowrap;
}text-middle
In
vertical-align,middleshould be calledtext-middle.
/* before */
button {
vertical-align: text-middle;
}
/* after */
button {
vertical-align: middle;
}background-size
In
background-size, having one value should duplicate its value, not default the second one toauto.
/* before */
header {
background-size: 75%;
}
/* after */
header {
background-size: 75% 75%;
}background-position
background-positionandborder-spacing(all 2-axis properties) should take vertical first, to match with the 4-direction properties likemargin.
/* before */
body {
background-position: 0% 50%;
}
table {
border-spacing: 10px 5px;
}
/* after */
body {
background-position: 50% 0%;
}
table {
border-spacing: 5px 10px;
}z-order
z-indexshould be calledz-order.
/* before */
aside {
z-order: 10;
}
/* after */
aside {
z-index: 10;
}overflow-wrap
word-wrap/overflow-wrapshould not exist, andoverflow-wrapshould be a keyword onwhite-space.
/* before */
a {
white-space: overflow-wrap;
}
/* after */
a {
word-wrap: break-word;
}corner-radius
border-radiusshould becorner-radius.
/* before */
button {
corner-radius: 3px;
}
/* after */
button {
border-radius: 3px;
}current-color
currentcolorshould becurrent-color.
/* before */
button {
box-shadow: 0 0 5px solid current-color;
}
/* after */
button {
box-shadow: 0 0 5px solid currentColor;
}rgb & hsl
rgba()andhsla()should not exist, andrgb()andhsl()should have an optional fourth alpha parameter (which should use the same format as R, G, and B or S and L).
/* before */
header {
background-color: rgb(0, 0, 255, 102);
color: hsla(170, 50%, 45%, 80%);
}
/* after */
header {
background-color: rgba(0, 0, 255, .4);
color: hsla(170, 50%, 45%, .8);
}Usage
Add Time Machine to your build tool:
npm install postcss-time-machine --save-dev
Node
require('postcss-time-machine')({ /* options */ }).process(YOUR_CSS);PostCSS
Add PostCSS to your build tool:
npm install postcss --save-dev
Load Time Machine as a PostCSS plugin:
postcss([
require('postcss-time-machine')({ /* options */ })
]);Gulp
Add Gulp PostCSS to your build tool:
npm install gulp-postcss --save-dev
Enable Time Machine within your Gulpfile:
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('postcss-time-machine')({ /* options */ })
])
).pipe(
gulp.dest('./css')
);
});Grunt
Add Grunt PostCSS to your build tool:
npm install grunt-postcss --save-dev
Enable Time Machine within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-time-machine')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});Options
Any feature of Time Machine may be disabled by passing a false value to its feature key.
Example:
require('postcss-time-machine')({
rgba: false
})Features include background-position, background-size, border-spacing, corner-radius, current-color, hsl, rgb, vertical-align, white-space, and z-order.