All Projects → saulhardman → postcss-hover-media-feature

saulhardman / postcss-hover-media-feature

Licence: MIT license
PostCSS plugin that extracts and wraps rules containing `:hover` pseudo-classes in `@media (hover: hover) {}` media queries

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to postcss-hover-media-feature

sublime-postcss-sorting
Sublime Text plugin to sort CSS rules content with specified order.
Stars: ✭ 19 (-59.57%)
Mutual labels:  postcss
vital
Starter template for Vite with React (TypeScript). Supports Tailwind with CSS-Modules. Jest and @react/testing-library configured and ready to go. Also ESLint, Prettier, Husky, Commit-lint and Atomic Design for components.
Stars: ✭ 151 (+221.28%)
Mutual labels:  postcss
tooltip-generator
💫 A tool to generate CSS code for tooltips. Built with Vue.js and Tailwind CSS
Stars: ✭ 32 (-31.91%)
Mutual labels:  postcss
stencil-boilerplate
A Stencil app boilerplate including routing, Redux etc.
Stars: ✭ 51 (+8.51%)
Mutual labels:  postcss
pwa
An opinionated progressive web app boilerplate
Stars: ✭ 355 (+655.32%)
Mutual labels:  postcss
postcss-center
PostCSS plugin to center elements.
Stars: ✭ 44 (-6.38%)
Mutual labels:  postcss
fylgja
The modular highly customisable CSS framework. Powered by CSS Components, Utilities and Props for building your Web UI.
Stars: ✭ 65 (+38.3%)
Mutual labels:  postcss
postcss-property-lookup
PostCSS plugin for property lookups, similar to Stylus
Stars: ✭ 67 (+42.55%)
Mutual labels:  postcss
alfred-postcss-workflow
Alfred App Workflow for https://www.postcss.parts
Stars: ✭ 14 (-70.21%)
Mutual labels:  postcss
faven
A web tool to help you generate favicons
Stars: ✭ 126 (+168.09%)
Mutual labels:  postcss
HoveringCallback
Drag & drop item decorator for RecyclerView with support for highlighting hovered items.
Stars: ✭ 15 (-68.09%)
Mutual labels:  hover
elm-tachyons-boilerplate
Simple setup for Elm and Tachyons
Stars: ✭ 17 (-63.83%)
Mutual labels:  postcss
vscode-ethover
Ethereum Account Address Hover Info and Actions
Stars: ✭ 35 (-25.53%)
Mutual labels:  hover
browser-extension
Browser Extension Template with ESbuild builds, support for React, Preact, Typescript, Tailwind, Manifest V3/V2 support and multi browser build including Chrome, Firefox, Safari, Edge, Brave.
Stars: ✭ 535 (+1038.3%)
Mutual labels:  postcss
sveltekit-starter
Sveltekit starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 482 (+925.53%)
Mutual labels:  postcss
mobileweb
webpack 5 + postcss 8 构建移动端网站架子
Stars: ✭ 23 (-51.06%)
Mutual labels:  postcss
tailwindcss
Add Tailwind CSS to your Svelte project
Stars: ✭ 583 (+1140.43%)
Mutual labels:  postcss
postcss
Add PostCSS to your Svelte project
Stars: ✭ 37 (-21.28%)
Mutual labels:  postcss
hover.el
Flutter tool to run hover on emacs
Stars: ✭ 38 (-19.15%)
Mutual labels:  hover
sapper-with-postcss-and-tailwind
Basic Sapper app with PostCSS + Tailwind
Stars: ✭ 23 (-51.06%)
Mutual labels:  postcss

PostCSS Hover Media Feature

NPM Version NPM Monthly Downloads Build Status

PostCSS plugin that extracts and wraps rules containing :hover pseudo-classes in @media (hover: hover) {} media queries.

Certain mobile browsers apply :hover styles on 'tap', which (in most cases) isn't desirable. By wrapping :hover styles with a Hover Media Feature Media Query these styles will only be applied on devices that support them.

.foo:hover {
  color: blue;
  text-decoration: underline;
}

/* becomes */

@media (hover: hover) {
  .foo:hover {
    color: blue;
    text-decoration: underline;
  }
}

Installation

Using npm:

> npm install --save-dev postcss postcss-hover-media-feature

Using Yarn:

> yarn add --dev postcss postcss-hover-media-feature

Usage

Check your project for an existing PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you already use PostCSS, add the plugin to plugins list:

// postcss.config.js
module.exports = {
  plugins: [
+   require('postcss-hover-media-feature'),
    require('autoprefixer')
  ]
}

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Options

fallback

Type: Boolean Default: false

The fallback option provides a way to extend this functionality to browsers that don't themselves support the Hover Media Feature. It prefixes rules whose selectors contain the :hover pseudo-selector – only when this selector is also matched will the hover styles apply.

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-hover-media-feature')({
      fallback: true
    })
  ]
}
.foo:hover {
  color: blue;
  text-decoration: underline;
}

/* becomes */

html:not(.supports-touch) .foo:hover {
  color: blue;
  text-decoration: underline;
}

@media (hover: hover) {
  .foo:hover {
    color: blue;
    text-decoration: underline;
  }
}

fallbackSelector

Type: String Default: html:not(.supports-touch)

Only relevant when fallback: true.

Specifies the selector that is prepended with a descendent combinator to selectors containing :hover pseudo-class.

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-hover-media-feature')({
      fallback: true,
      fallbackSelector: '.supports-hover'
    })
  ]
}
.foo:hover {
  color: blue;
  text-decoration: underline;
}

/* becomes */

.supports-hover .foo:hover {
  color: blue;
  text-decoration: underline;
}

@media (hover: hover) {
  .foo:hover {
    color: blue;
    text-decoration: underline;
  }
}

rootSelectors

Type: Array[String] Default: []

Only relevant when fallback: true.

Accepts an array of selectors that match the :root element (i.e. <html>) so that fallbackSelector is chained rather than prepended with descendent combinator.

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-hover-media-feature')({
      fallback: true,
      rootSelectors: ['.t-dark']
    })
  ]
}
.t-dark .foo:hover {
  color: white;
}

/* becomes */

html:not(.supports-touch).t-dark .foo:hover {
  color: white;
}

@media (hover: hover) {
  .t-dark .foo:hover {
    color: blue;
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].