CSS Pseudo-classes: Other states

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

This is the last series in the CSS pseudo-class exploration. These are pseudo-classes that did not fit any of the previous categories.
I've split this up into a series of four, where this is the last part about other pseudo-states.
The other parts:
As for the other ones, we have the following that we can explore.
:is:not:has:isThis selector can be used to match multiple elements on the go.
You might have seen the following in standards CSS before:
div strong,
div i {
color: hotPink;
}
This will make all strong and italic elements in a div pink.
However, we can leverage the :is selector to make this a bit more cleaner.
div :is(strong, i) {
color: hotPink;
}
I really like this selector and have been using it more lately. It cleans up classes.
Try it out in this CodePen.
:notMuch like the above :is selector, this one does the opposite and fires if it's NOT one of the mentioned elements.
We want to style all elements, but the strong and italic ones.
div :not(strong, i) {
color: hotPink;
}
And another cool thing we can do with this selector is validating on even more queries.
img:not([alt]) {
outline: 10px solid red;
}
The above example will put a big red outline around images missing the alt attribute.
Note: check out this article for more information about CSS attribute selectors
Try both out in this CodePen.
I also have a complete article on the CSS :not selector if you want some more details.
:hasThis is not a stable solution yet, but super excited this is coming out!
So far, you can only use this in the Safari Technology preview version. But it's super exciting to see what we can do with it.
We can target a parent that contains certain children.
div:has(p) {
background: yellow;
}
This would select all divs that have paragraph elements.
Some use-cases would be to remove margin from a header if it has a subtitle, for instance:
.header {
margin: 1;
}
.header:has(.subtitle) {
margin: 0;
}
Keep an eye out for this one, as it will become a big change for what we can do with CSS.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter