:is() and :where() - The New Functional Pseudo-class Selectors
Photo by Sigmund on Unsplash

:is() and :where() - The New Functional Pseudo-class Selectors

Meet the new Pseudo-class Selectors of the CSS family.

:is() and :where().

What's their need, how they are changing the code, and a lot more questionnaires? The same was happening to me too. After reading the blogs and practical examples, I understood that necessity.

Sharing my understanding, with all of you CSS folks out there.

Example:

.header h1,
.header p,
.header button,
.header :button{
  color: tomato;
  font-size: 1.2rem;
}        

These huge selectors on the above snippets which are separated by [, ](comma) seem normal, but theirs one gotcha! If any of one is wrong declared, these all will be ignored by the browser. and instantly the code becomes garbage.

So, these selectors are basically forgiving you for errors.


.header :is(h1, p, button, :button){
  color: tomato;
  font-size: 1.2rem;
}        

Even, if the last selector element is invalid but the browser will not invalidate you whole code. Saviour!!!

Difference in :is() vs :where()

  • :where() has no specificity.
  • :is() will take the specificity of the highest among the parameters

Thanks for reading. Comment your questions as well.

要查看或添加评论,请登录

Shivam Gupta的更多文章

  • Conversion Rate Optimization

    Conversion Rate Optimization

    Introduction: Conversion Rate Optimization (CRO) is the process of improving the percentage of website or app visitors…

  • How to create a VueJS app with TypeScript

    How to create a VueJS app with TypeScript

    Back with another blog, You have already listened to the hype of TypeScript like why people prefer type-safety nowadays…

  • The CSS Shorthands - Part 1??

    The CSS Shorthands - Part 1??

    TLDR; You can scroll to snippets directly. The best thing about CSS is, it keeps on evolving.

  • How to write a Kickass GitHub Readme ??

    How to write a Kickass GitHub Readme ??

    GitHub recently rolled out a brand new feature of creating profile-level "Readme" to showcase your skills. Yes, it can…

社区洞察

其他会员也浏览了