GoScrobble/web/node_modules/css-blank-pseudo
2022-04-25 14:48:54 +12:00
..
browser-legacy.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
browser.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
CHANGELOG.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
cli.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.js.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.mjs 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
index.mjs.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
legacy.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
legacy.js.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
legacy.mjs 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
legacy.mjs.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
LICENSE.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
package.json 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
postcss.js 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
postcss.js.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
postcss.mjs 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
postcss.mjs.map 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00
README.md 0.2.0 - Mid migration 2022-04-25 14:48:54 +12:00

CSS Blank Pseudo

NPM Version Build Status Support Chat

CSS Blank Pseudo lets you style form elements when they are empty, following the Selectors Level 4 specification.

input {
  /* style an input */
}

input:blank {
  /* style an input without a value */
}

Usage

From the command line, transform CSS files that use :blank selectors:

npx css-blank-pseudo SOURCE.css TRANSFORMED.css

Next, use your transformed CSS with this script:

<link rel="stylesheet" href="TRANSFORMED.css">
<script src="https://unpkg.com/css-blank-pseudo/browser"></script>
<script>cssBlankPseudo(document)</script>

Thats it. The script is 509 bytes and works in all browsers.


If you support Internet Explorer 11, use the browser legacy script, which is 671 bytes:

<link rel="stylesheet" href="TRANSFORMED.css">
<script src="https://unpkg.com/css-blank-pseudo/browser-legacy"></script>
<script>cssBlankPseudo(document)</script>

How it works

The PostCSS plugin clones rules containing :blank, replacing them with an alternative [blank] selector.

input:blank {
  background-color: yellow;
}

/* becomes */

input[blank] {
  background-color: yellow;
}

input:blank {
  background-color: yellow;
}

Next, the JavaScript library adds a blank attribute to elements otherwise matching :blank natively.

<input value="" blank>
<input value="This element has a value">