Skip to content

Instantly share code, notes, and snippets.

@rootulp
Last active January 15, 2019 01:12
Show Gist options
  • Save rootulp/105d3287c59824ad08ef to your computer and use it in GitHub Desktop.
Save rootulp/105d3287c59824ad08ef to your computer and use it in GitHub Desktop.
CSS Specificity - Lightning Talk

Specificity determines, which CSS rule is applied by browsers.

General Rule: You want to be as specific as it makes sense to be. If some styling isn't applied to an element, check the specificity.

Most specific to least specific
  1. Inline Styles

An inline style lives within your HTML document. It is attached directly to the element to be styled.

<h1 style="color: #fff;">

  1. IDs

#id_name{}

  1. Classes, Attributes, and Pseudo-classes

    Classes: .class_name{}

    Attributes: span[lang]{}

    Pseudo-class: a:hover{} a:focus{}

  2. Elements and Pseudo-elements

    Elements: p{} h3{}

    Pseudo-elements: :before{} :after{}

Specificity is actually a value attributed to each CSS selector. Read about it here

Resources:

Brief overview

Mozilla docs

@stcrestrada
Copy link

Great presentation. Speak up though.

Thanks, Stephen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment