Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created March 12, 2013 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/5143114 to your computer and use it in GitHub Desktop.
Save joyrexus/5143114 to your computer and use it in GitHub Desktop.
Overview of basic CSS selectors.
/* basic */
#foo {} /* id */
.bar {} /* class */
a#foo.bar {} /* element attribute combinations */
/* attributes */
#foo a[href] {} /* simple */
#foo a[href=bar] {} /* attribute values */
#foo a[lang|=en] {} /* subcodes */
#foo a[title~=hello] {} /* attribute contains */
#foo a[href^="http://"] {} /* attribute starts with */
#foo a[href$=com] {} /* attribute ends with */
#foo a[href*=twitter] /* {} attribute wildcards */
/* descendants */
#foo a {} /* all descendants */
ul#list > li {} /* direct children */
/* siblings */
span ~ strong {} /* all adjacent */
p + p {} /* immediate adjacent */
/* combos */
div,p {}
/* variations */
#foo.bar.baz {}
div#baz.thunk a[-data-info*="hello world"] span + strong {}
#thunk[title$='huzza'] {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment