Skip to content

Instantly share code, notes, and snippets.

@viclafouch
Last active June 27, 2021 18:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save viclafouch/157c2572d8235f4ebd1305b69b82f964 to your computer and use it in GitHub Desktop.
Save viclafouch/157c2572d8235f4ebd1305b69b82f964 to your computer and use it in GitHub Desktop.
Lint CSS
/* Prevent unsecure [target="_blank] links */
a[target='_blank']:not([rel~='noopener']):not([rel~='noreferrer']) {
outline: 2px dashed red;
}
/* Input or label without id or for attribute */
input:not([id]),
label:not([for]) {
outline: 2px dashed red;
}
/* Headers out of order */
:is(h2, h3, h4, h5, h6) ~ h1,
:is(h3, h4, h5, h6) ~ h2,
:is(h4, h5, h6) ~ h3,
:is(h5, h6) ~ h4,
h6 ~ h5 {
outline: 2px dashed red;
}
/* Images without alt attribute */
img:not([alt]) {
outline: 2px dashed red;
}
/* Div inside inline elements */
:is(b, i, q, em, abbr, cite, code, span, small, label, strong) > div {
outline: 2px dashed red;
}
/* Lang attribute in html document */
html:not([lang]):before {
display: block;
content: "You didn't declare lang attribute";
color: red;
}
/* <picture> elements that do not contain .webp <source> */
picture > source:first-child:not([type="image/webp"])::before {
content: "Missing a webp source";
padding: 1em;
display: block;
outline: 2px solid aqua;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment