Irina Glushko 2389e7160b HW1 done | 3 лет назад | |
---|---|---|
.. | ||
CHANGELOG.md | 3 лет назад | |
LICENSE.md | 3 лет назад | |
README.md | 3 лет назад | |
browser-legacy.js | 3 лет назад | |
browser.js | 3 лет назад | |
cli.js | 3 лет назад | |
index.js | 3 лет назад | |
index.js.map | 3 лет назад | |
index.mjs | 3 лет назад | |
index.mjs.map | 3 лет назад | |
legacy.js | 3 лет назад | |
legacy.js.map | 3 лет назад | |
legacy.mjs | 3 лет назад | |
legacy.mjs.map | 3 лет назад | |
package.json | 3 лет назад | |
postcss.js | 3 лет назад | |
postcss.js.map | 3 лет назад | |
postcss.mjs | 3 лет назад | |
postcss.mjs.map | 3 лет назад |
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 */
}
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>
That’s 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>
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">