Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How much are specificity hacks used? #27

Open
LeaVerou opened this issue Jul 17, 2020 · 2 comments
Open

How much are specificity hacks used? #27

LeaVerou opened this issue Jul 17, 2020 · 2 comments
Labels
✅ Has algorithm (1/3) An implementable algorithm for how to measure this stat has been described in the issue ✅ Has JS (2/3) JS has been written to calculate this stat ✅ Has SQL (3/3) BigQuery SQL has been written to calculate this stat. proposed stat Proposed statistic to study Section: Selectors

Comments

@LeaVerou
Copy link
Owner

By specificity hacks I mean selector rewritings or additions with the sole purpose of increasing or decreasing specificity. Things like:

  • [id=foo]
  • .foo.foo.foo
  • :not(#nonexistent) .actual-selector
    etc

I suppose BEM could also be considered a specificity hack.

@LeaVerou LeaVerou added the proposed stat Proposed statistic to study label Jul 17, 2020
@LeaVerou LeaVerou mentioned this issue Jul 20, 2020
@bradkemper
Copy link

Also, html or html body at the beginning of a selector, to just bump it up a little.

@LeaVerou
Copy link
Owner Author

LeaVerou commented Sep 16, 2020

Algorithm:

Walk selectors, and count:

  • ids in attribute equality
  • compound selectors with the same class name more than once
  • Descendant selectors with html or :root as the first one.
  • Descendant selectors where the first one is :not(#id). This is meaningless in terms of selector logic, so it has to be a specificity hack.
  • Selectors that are entirely classes that look like BEM (/^(?=.+--|.+__)[a-z0-9-]+(__[\w-]+)?(--[\w-]+)?$/i) or descendants and such classes

@LeaVerou LeaVerou added ✅ Has algorithm (1/3) An implementable algorithm for how to measure this stat has been described in the issue and removed ⚠️ Needs algorithm labels Sep 16, 2020
@LeaVerou LeaVerou added ✅ Has JS (2/3) JS has been written to calculate this stat and removed ⚠️ Needs JS Needs JS to calculate this stat labels Sep 17, 2020
LeaVerou added a commit that referenced this issue Sep 17, 2020
@rviscomi rviscomi added ✅ Has SQL (3/3) BigQuery SQL has been written to calculate this stat. and removed ⚠️ Needs SQL Needs SQL to calculate this stat labels Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Has algorithm (1/3) An implementable algorithm for how to measure this stat has been described in the issue ✅ Has JS (2/3) JS has been written to calculate this stat ✅ Has SQL (3/3) BigQuery SQL has been written to calculate this stat. proposed stat Proposed statistic to study Section: Selectors
Projects
None yet
Development

No branches or pull requests

3 participants