:enter
:enter lets you use the proposed :enter
pseudo-class in CSS.
:enter
simplifies selectors targeting elements that are designated, as the naming of :hover
is somewhat misleading; it specifically means elements designated with a pointing device, rather than any device.
nav :enter > span {
background-color: yellow;
}
nav :hover > span,
nav :focus > span {
background-color: yellow;
}
From the proposal:
The :enter
pseudo-class applies while the user designates an element with a keyboard, pointing device, or other form of input. It matches an element if the element would match :focus
or :hover
.
Options
prefix
Type: String
Default: -
Adds the prefix surrounded by dashes before the pseudo-class.
outline
Type: String
Default: unset
Adds an outline declaration to matching rules when an existing one does not already exist.
Usage
Follow these steps to use :enter.
Add :enter to your build tool:
npm install postcss-pseudo-class-enter --save-dev
Node
require('postcss-pseudo-class-enter')({ }).process(YOUR_CSS);
PostCSS
Add PostCSS to your build tool:
npm install postcss --save-dev
Load :enter as a PostCSS plugin:
postcss([
require('postcss-pseudo-class-enter')({ })
]);
Gulp
Add Gulp PostCSS to your build tool:
npm install gulp-postcss --save-dev
Enable :enter within your Gulpfile:
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('postcss-pseudo-class-enter')({ })
])
).pipe(
gulp.dest('./css')
);
});
Grunt
Add Grunt PostCSS to your build tool:
npm install grunt-postcss --save-dev
Enable :enter within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-pseudo-class-enter')({ })
]
},
dist: {
src: 'css/*.css'
}
}
});
Alternatives
Below are some other methods to recreate the effects of :enter
.
Use @custom-selector (supported nowhere yet)
@custom-selector :--enter :focus, :hover;
:--enter { }
Use :matches (supported in Firefox 4+, Chrome 12+, Opera 15+, Safari 5.1+)
:matches(:focus, :hover) { }
Use :focus and :hover (supported everywhere)
:focus, :hover { }
Use Sass mixins (requires preprocessing)
@mixin -enter { &:focus, &:hover { @content; } }
@include -enter { }