Comments on: The CSS :has Selector (and 4+ Examples) https://css-tricks.com/the-css-has-selector/ Tips, Tricks, and Techniques on using Cascading Style Sheets. Tue, 20 Dec 2022 17:42:26 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Someone https://css-tricks.com/the-css-has-selector/#comment-1796790 Sun, 21 Aug 2022 09:05:57 +0000 https://css-tricks.com/?p=336424#comment-1796790 What does article:has(h2, ul) mean?

]]>
By: Steven https://css-tricks.com/the-css-has-selector/#comment-1796625 Fri, 05 Aug 2022 08:26:01 +0000 https://css-tricks.com/?p=336424#comment-1796625 Is it also possible to combine a CSS selector with an CSS operator?

I’m trying to highlight a table row where one of the cells contains

So my:

tbody.plugins tr td.plugin-title p img[src*=”pluginname”] { background-color: var(–postpone-update-alert) !important; }

Needs to become something like:

tbody.plugins tr:has(td.plugin-title p img[src*=”pluginname”]) { background-color: var(–postpone-update-alert) !important; }

as I want to apply the highlighting to the entire row but that doesn’t work…

Is it possible at all? Or am I just overlooking something?

]]>
By: Qbin2001 https://css-tricks.com/the-css-has-selector/#comment-1794121 Mon, 21 Feb 2022 13:15:45 +0000 https://css-tricks.com/?p=336424#comment-1794121 In reply to Is Deneyimlerim.

div:has(p) – “color” is used for all content of this “div” – but only if this “div” contains “p” tag.

div p – “color” is used only in “p” tags in “div”.

]]>
By: Is Deneyimlerim https://css-tricks.com/the-css-has-selector/#comment-1787452 Tue, 28 Dec 2021 07:42:35 +0000 https://css-tricks.com/?p=336424#comment-1787452 Everything is OK but the stones did not fit properly :)

What is the difference with two things:

div:has(p) {color: #000}
div p {color: #000}

Why should I use :has() selector?

]]>
By: Taufik Nurrohman https://css-tricks.com/the-css-has-selector/#comment-1787430 Mon, 27 Dec 2021 23:54:57 +0000 https://css-tricks.com/?p=336424#comment-1787430 This could be used as alternative to :*-within pseudo-classes.

div:has(:focus) {}
div:has(:hover) {}
div:has(:target) {}

No?

]]>
By: Tom Bower https://css-tricks.com/the-css-has-selector/#comment-1771754 Sat, 08 May 2021 17:40:39 +0000 https://css-tricks.com/?p=336424#comment-1771754 In reply to Bojan Petrovic.

It will be possible when :has() is supported, yeah.

A:has(B.red) { ... }
A:has(B.green) { ... }
A:has(B.blue) { ... }

]]>
By: Bojan Petrovic https://css-tricks.com/the-css-has-selector/#comment-1771292 Tue, 27 Apr 2021 15:03:30 +0000 https://css-tricks.com/?p=336424#comment-1771292 Hi, I have a question.

We have parent element A
and within it, we have child element B

<A>
<B></B>
</A>
<A>
<B></B>
</A>
<A>
<B></B>
</A>

Each element B gets a class in which its background color is for example, so the code looks like this :

<A>
<B class="red"></B>
</A>
<A>
<B class="green"></B>
</A>
<A>
<B class="blue"></B>
</A>

My question is, is it possible to set the background color of parent element A in relation to the background color of its child element B ???

TNX :)

]]>
By: Valentin Born https://css-tricks.com/the-css-has-selector/#comment-1771080 Thu, 22 Apr 2021 11:43:44 +0000 https://css-tricks.com/?p=336424#comment-1771080 In reply to josh-8805.

won’t be able to come until we find a workaround for the cyclical referencing issue

Which is something I never fully understood – couldn’t we just let the developers take care of resolving those? After all, it works for other stupid mistakes where we may shoot ourselves in the foot, e. g. p:hover {transform: scale(0.9)} may result in some jittery business along the edges, but that is for us devs to take care of.

]]>
By: Blake Frenchman https://css-tricks.com/the-css-has-selector/#comment-1771052 Wed, 21 Apr 2021 17:50:14 +0000 https://css-tricks.com/?p=336424#comment-1771052 In reply to Knoj.

yes dude

]]>
By: Tristin Hettinger https://css-tricks.com/the-css-has-selector/#comment-1770835 Thu, 15 Apr 2021 20:18:33 +0000 https://css-tricks.com/?p=336424#comment-1770835 In reply to Christopher Kirk-Nielsen.

:how() would that work?

]]>
By: Knoj https://css-tricks.com/the-css-has-selector/#comment-1770676 Mon, 12 Apr 2021 12:56:14 +0000 https://css-tricks.com/?p=336424#comment-1770676 I eagerly await the adoption of :has(). Imagine:

body:has(.printarea) {
    // Content creator has provide a div with a class of "ptintarea" they want printed.  Hide everything else.
}

Currently, the only way to check for this is to use JS. A clean way to do it in CSS would be lovely!

Plenty of other fantastic possibilities too!

Do we know if it will nest?
div:has(a:has(img)) ???
Ick… that’s not great for readability though.

]]>
By: Nothrem https://css-tricks.com/the-css-has-selector/#comment-1770520 Tue, 06 Apr 2021 07:55:56 +0000 https://css-tricks.com/?p=336424#comment-1770520 Selector :not() was defined in CSS3 but it could contain only one selector. Still it’s very useful if you know what you are doing (e.g. div:not(.hidden) { display: block }) or need to shorten some more advanced selectors (e.g. li:not(:first-of-type):not(:last-of-type) { … } )

]]>
By: gotofritz https://css-tricks.com/the-css-has-selector/#comment-1770316 Tue, 30 Mar 2021 14:39:05 +0000 https://css-tricks.com/?p=336424#comment-1770316 The :has pseudo selector has been in the wishlist for years, perhaps even more than a decade… but browser vendors have repeated again and again that it’s impossible to implement. Until we hear noises to the contrary, I wouldn’t waste my time with it

]]>
By: Karl Swedberg https://css-tricks.com/the-css-has-selector/#comment-1770240 Sun, 28 Mar 2021 01:57:59 +0000 https://css-tricks.com/?p=336424#comment-1770240 Support for this as a CSS selector would be fantastic. I found it quite useful back in the day when I used jQuery a lot (see https://api.jquery.com/has-selector/).

]]>
By: Anders Grimsrud https://css-tricks.com/the-css-has-selector/#comment-1769932 Fri, 19 Mar 2021 06:08:41 +0000 https://css-tricks.com/?p=336424#comment-1769932 In reply to Jaisankar.

These are regular CSS selector combinators. You can find them all over at MDN and read more about them at CSS tricks :-)

]]>