Q: How can you use :has()
together with ::after
?
A: By using a browser that has support for :has()
.
Safari so far is the only browser where the current stable version supports :has()
(since version 15.4, we're at 15.6.1 as of now).
Chrome is going to support it in the next stable version 105 which is going to be released in 5 days from now, August 30, 2022.
Firefox has been supporting it behind a flag since version 103. It can be enabled by entering about:config
in the address bar and then enabling layout.css.has-selector.enabled
(set it to true
).
This is how your snippet renders in current Safari (MacOS):

which shows Safari is applying your rule
div:has(button:not([style*="display: none"]))::after {
content: 'not working';
}