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.