Arslan Khalid Profile picture
Building @topcampH to enable the tech ecosystem of Pakistan by training the next generation of developers.

Sep 11, 2020, 9 tweets

A ๐Ÿงตabout CSS Selectors:

Going from Easy -> Complex...

๐Ÿ‘‡

These are the commonly used CSS selectors:

1. Universal Selector ( * )

2. Element Selector ( p , a , div , ... )

3. Class Selector ( .my-class )

4. Id Selector ( #CSS ๐Ÿ˜‰)

๐Ÿ‘‡

5. Attribute Selectors

๐Ÿ‘‡

Attribute Selectors with Regular Expressions (Regex):

Crazy right. Let's explore.

๐Ÿ‘‡

6. Complex Selectors

They use different combinators like:

a. Descendant combinator ( space )

b. Child combinator ( > )

c. Sibling combinator ( + )

d. Subsequent combinator ( ~ )

Let's see what they do:

๐Ÿ‘‡

Note:

The descendant combinator (space) is recursive. For example:
ul li {...}
will style all the 'li' elements inside 'ul' even if the 'li' does not have 'ul' as direct parent.

Use it with caution!

It is advised to use child combinator ( > ) to avoid recursive styling.

๐Ÿ‘‡

7. Compound Selectors

As the name suggests they are a combination of different selectors.

Let's see it in practice.

๐Ÿ‘‡

Last but not least!

The Rulers of the Phantom World:

Pseudo Elements and Pseudo Classes.

They deserve a thread of their own but here's a teaser:

๐Ÿ‘‡

These are the selectors available at your disposal to make wonderful experiences on the world wide web.

Go make something beautiful.

Thanks for reading.

More coming in the pipeline. Stay tuned.

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling