Hello for everyone. This article we talk about the Different CSS SelectorsWeb Development, I hope this lesson is useful for you.

Why are the used? CSS Selectors

CSS Selectors are used for targeting HTML elements from our web page to style them.

Types of Selectors



ID SELECTORS #sapien {}


SelectorExample Example Description
.class .introSelects all elements with class=”intro”
.class1.class2.name1.name2Selects all elements with both name1 and name2 set within its class attribute
.class1.class2.name1 .name2Selects all elements with name2 that is a descend of an element with name1
#id#firstnameSelects all elements with id=”firstname”
**Selects all elements
elementpSelects all <p> elements
element.classp.introSelects all <p> elements with class=”intro”
element,elementdiv, pSelects all <div> elements and all <p> elements
element elementdiv p Selects all <p> elements inside <div> elements
element>elementdiv > pSelects all <p> elements where the parent is a <div> element
The below table is more Continuation
The below table is not different table
:activea:activeSelects the active link
::afterp::afterInsert something after the content of each <p> element
::beforep::beforeInsert something before the content of each <p> element
:checkedinput:checkedSelects every checked <input> element
:default input:defaultSelects the default <input> element
:disabledinput:disabledSelects every disabled <input> element
::emptyp:emptySelects every <p> element that has no childern (including text nodes)
:enabledinput:enabledSelects every enabled <input> element
:first-childp:first-childSelects every <p> element that is the first child of its parent
::first-lettterp::first-letterSelects the first letter of every <p> element
::first-linep::first-lineSelects the first letter of every <p> element
Selects every <p> element that is the first <p> element of its parent

The Source: https://www.instagram.com/tech.sapien/