Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 6780

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T09:43:11+00:00 2024-11-27T09:43:11+00:00

Fun with CSS combinators

  • 60k

As part of the comiCSS webcomic, I drew a short cartoon to explain how the combinators (and the universal selector) work. Hopefully, it helps illustrate how the CSS combinators work and what elements would be impacted by them:

Cartoon with panels showing a bar with 3 people, a CSS combinator saying 'hey waiter! our next round on me!', and 3 more people. First, the child combinator (>) invites and someone off-panel says 'thanks, dad!'. Then, the adjacent sibling combinator (+) invites, and the person to its right thanks it. The general sibling combinator (~) invites, all the people to its right cheer. The universal selector (*) invites, all cheer. Finally the column combinator (||) invites, the other combinators thank.

It doesn't include the descendant combinator because it would be just a blank space and it would be weird to do that in comic form. Just an empty space in the middle of the panel 😅

Some theory

A CSS combinator is a tool that combines selectors, providing additional meaning and expressing relationship between them. 

There are five CSS combinators:

  • Descendant combinator (): indicates that the second element is a descendant (at any level) of the first one. Example: a b will select all the <b> that are inside of an <a>.
  • Child combinator (>): specifies that the second element is a direct descendant (first level only) of the first one. Example: a > b will select all the <b> that are direct children of an <a>.
  • Adjacent sibling combinator (+): indicates that the second element follows the first one directly in the code (first sibling). Example: a + b will select all the <b> that directly follow an <a>.
  • General sibling combinator (~): states that the second element follows the first one in the code (any sibling as long as it's after the first element). Example: a ~ b will select all the <b> that follow (siblings) an <a>.
  • Column combinator (||): indicates that the second element is in the same column as the first element.

The column combinator is considered experimental. No browser supports it now, and it is at risk of being removed from the standard. So probably not a good idea to use it in production.

If you noticed, the reply to the column combinator is in blue instead of yellow: the ones answering are the other combinators as they are in the same column! 😉

Combinators and Specificity

This may sound a bit counterintuitive, but CSS combinators do not add to the specificity of a selector. This means that things like a b and a > b have the same specificity (even when one is more specific logically than the other.)

This is the way it is and it will likely never change, as they explain on this thread of the W3C working group mailing list. Giving a specificity value to the combinators would:

  • add complexity to the specificity calculations;
  • impact the styling of existing sites.

The first point is arguable. The second one present a bigger challenge: if the specificity was not changed because it would impact many existing websites almost 20 years ago, imagine how many more it could impact now.


If you enjoy this type of cartoons, visit comiCSS: a webcomic about CSS, coded in CSS. Or check the code on GitHub (it is a publicly built project.)

cssjokewebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.