Ashish Kumar Profile picture
Feb 10 β€’ 20 tweets β€’ 5 min read
⚑ Learn CSS selectors in one thread ⚑

The only thread you need to learn about CSS Selectors.

A Mega Thread 🧡
πŸ‘‰ CSS, selectors are used to target the HTML elements on our web pages that we want to style. There are a wide variety of CSS selectors available, allowing for fine-grained precision when selecting elements to style.
πŸ‘‰ A selector is the first part of a CSS Rule. Typically a pattern or term decides which HTML element it needs to select. The Elements that are selected are called subjects of the selector.
πŸ‘‰ Selector lists: If you have two elements that have the same styling then you can combine both of the selectors to make a selectors list. we use commas for this.

Example: Image
πŸ‘‰ Types of selectors: There are different groups of selectors that serve various use cases while selecting elements
➑ Universal selector
➑ Type, class, and ID selectors
➑ Attribute selectors
➑ Pseudo-classes and pseudo-elements
➑ Combinators
➑ Universal selector: Universal Selectors are the one that selects all the elements of an HTML Page. It is generally used for CSS resets and applying global styles.

Example: Image
πŸ‘‰ Type, class, and ID selectors: These are used for selecting HTML Elements, and these targets HTML elements.

➑ Element Selector
➑ Class selector
➑ ID selector
πŸ‘‰ Element Selector: This basically selects an element by its element name, using this will select all the elements on the page when specified.

If we select <p> element it will by default select all <p> elements in the page. we use 'tag' for this.

Example: Image
πŸ‘‰ Class selector: This selector selects the specific class in an HTML page. It is generally used for styling multiple elements. Will style all the elements which will have the same class name.
we use ' . ' for this.

Example: Image
πŸ‘‰ ID selector: These are used to select a unique item that you need to style. Id can't be repeated it should be unique. so if you want to style something with id use this. we use ' # ' for this.

Example: Image
πŸ‘‰ Attribute selectors: These are the Selectors that allow selecting elements based on certain attributes on an element.

Example: Image
πŸ‘‰ Pseudo-classes: Pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s).

Example: Image
πŸ‘‰ Pseudo-elements: Pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s).

Example: Image
πŸ‘‰ Combinators: These selectors combine other selectors in order to target elements within our documents.

➑ Descendant combinator
➑ Child combinator
➑ Adjacent sibling combinator
➑ General sibling combinator
πŸ‘‰ Descendant combinator: A descendant selector in CSS is any selector with white space between two selectors without a combinator.

Example:
ul li { } for example. It means β€œany list item that is a descendant of an unordered list.” Image
πŸ‘‰ Child combinator: A child combinator in CSS is the β€œgreater than” symbol. It means β€œselect elements that are direct descendants only”.

Example:
codepen.io/team/css-trick…
πŸ‘‰ Adjacent sibling combinator: The adjacent sibling combinator in CSS isn’t a selector on its own, but a way of combining two selectors.

Example:
codepen.io/saracope/pen/p…
πŸ‘‰ General sibling combinator: The general sibling combinator selector is very similar to the adjacent sibling combinator selector The difference is that the element being selected doesn’t need to immediately succeed the first element, but can appear anywhere after it.
πŸ‘‰ CSS Selector Reference Table.

Source: MDN. Image
Hey Everyone πŸ‘‹ I am Ashish.

Helping you become a better web developer.
Daily content on Web development tips, threads, and dev tools.

If you find this helpful then.
πŸ‘‰ Follow me
❀️ Like it
πŸ” Retweet the first tweet.

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Ashish Kumar

Ashish Kumar Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Ashish_feels

Feb 19
7 Free Javascript Books/Guides that will help you boost your JavaScript Knowledge. πŸ’―

A Thread 🧡 πŸ‘‡
πŸ‘‰ Eloquent JavaScript: eloquentjavascript.net

Amazing Book for beginners.
πŸ‘‰ JavaScript The Right Way: jstherightway.org

Basics to Design Patterns all covered.
Read 9 tweets
Feb 19
Are you learning JavaScript? πŸ€”

This knowledge map is certainly gonna help you. πŸ’―

Must-know topics while learning JavaScript in a single Place.

Links for the resource in comments πŸ‘‡
Read 4 tweets
Feb 15
12 Github Repos that will make you a better Javascript Developer. πŸ’―

A Thread 🧡 πŸ‘‡
Read 14 tweets
Feb 5
πŸš€ Crack your next Job Interview with Github.

πŸ‘‰ Collection of Github repositories that will help you crack your next interview.

A Thread 🧡 πŸ‘‡
Read 24 tweets
Feb 4
πŸš€ Learn Javascript Objects in One Thread πŸš€

Still, confused about Javascript Objects?

😳 😳 😳

Here is a Thread that will help you learn Objects in Javascript in an easy way.

😎 😎 😎

A thread to Bookmark 🧡
Read 9 tweets
Jan 30
πŸš€ Do you love Tailwind CSS?

πŸš€ Or Want to Learn Tailwind CSS?

Here is my amazing collection of Tailwind CSS Tips Collection for web developers that I have shared on Twitter so far.

πŸš€ Making CSS easy, Tailwind CSS.

A Thread of Tailwind Tips 🧡
Read 15 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

:(