🎁 The Js-Craft Guide to React is now available with a 30% off discount!

What is the :is() CSS pseudo-class and how it is helpful

The :is() gets a list of arguments and applies the given rules to the all elements that are matching on of the selectors in the list. For example:

p:is(.main, .front) {
    font-weight: bold;
}
/* will make bold any p element that 
has at least a class of main or front */

This is a less verbose way of writing a list of CSS selectors.

p.main, 
p.front {
    font-weight: bold;
}

We can pass it anything, not just classes. We can use it in conjunction with ids, classes, tags etc.

:is(h1, h2) {....}
.login:is(div, #main, .invaid) {...}

The specificity will equal that of the passed selector with the highest specificity. So, :is(#main, div) will have the specificity of the #main - 1.0.0 and :is(h1, form) will have a specificity of 0.0.1.

Also one cool thing about the :is() selector is that it will work even if one argument is not valid. As the opposite of the classical way of writing CSS when having one invalid selector will cancel the full list.

p, 777 {...};
/* will not work not even for the p elements*/
:is (p, 777) {....}
/* will not work for the p elements*/

This makes it great to be used within selectors that are not yet fully supported in all browsers.

:is(p, webkit-unsuported-suff-here) {...}
/*will still work for the p elements*/ 

The cross-browser support is pretty good.

10 Javascript AI projects with Langchain & React

Not sure what to build? Dive in with these Javascript AI projects! Learn how to build LLM powered apps using Langchain.js and React! Connect your apps to LLMs such as OpenAI, create agents, use vector databases, or setup AI context.

10 Javascript AI projects with Langchain & React

Not sure what to build? Dive in with these Javascript AI projects! Learn how to build LLM powered apps using Langchain.js and React! Connect your apps to LLMs such as OpenAI, create agents, use vector databases, or setup AI context.


Leave a Reply

Your email address will not be published. Required fields are marked *

📘 The Guide to React Home Screencasts Best of Newsletter Search X

📘 - 10 Javascript AI projects with React and LangChain

Hi friend! Before you go, just wanted to let you know about the 10 Javascript AI projects ideas with React and LangChain FREE ebook.

One of the best ways to learn is by doing the work. Choose from these 10 project ideas and start working on topics such as:

  • How does LangChain work
  • Connecting to OpenAI LLM
  • Create AI Agents
  • Simple and Sequential Chains
  • Adding Memory (Chat Context)
  • Prompt Templates
  • Using OutputParsers and Tools for Agents
  • Work with Documents and more...

Keep building and see the new capabilities LLM models can add to your React app! Get all projects as an ebook right to your inbox!

X