Home > UI/UX Development > CSS > Selectors! Types and difference

Selectors! Types and difference

Basic Selectors:

  1. Universal Selector: 
  2. ID, Class Selector
  3. Element/ Tag Selector
  4. Attribute Selector
  5. Descendant Selector: Selects all elements(any level deep) that are under the selector. For ex. following code will select all the span elements that are inside div element.

selector1

  1. Child Selector: Selects all elements that are one level under the selector. For ex. following code will select all the span elements at first level that are inside div element.

selector2

  1. General Sibling: Selects all elements that are adjacent to the first selector. For ex. following code will select all the span elements that are adjacent to div element and are placed after div in the DOM.

selector3

  1. Adjacent Sibling Selector: Selects first element that is adjacent to the first selector. For ex. following code will select the first span element that is adjacent to div element and is placed after div in the DOM.

NOTE: If any other element apart from span ex. p tag is between div and span then the above selector will not select anything
selector4


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">