How to target a tag that has no parents?

I am playing with userContent.css in Firefox which allows me to inject a stylesheet into every page. I have several SVGs that include a @media (prefers-color-scheme: dark) rule to display differently on dark monitors. My issue is the default background for a SVG opened by itself is "transparent", but is effectively white. I tried adding a @media (prefers-color-scheme: dark) { svg { background-color: #0008 } } style, which worked, but it affects every SVG on every page, & generally makes the browser look crappy. I want to just target the background of SVGs when they are the root of the DOM. I tried :root > svg, but that doesn't work. ¿Anyone got a clue❔
4 Replies
Mannix
Mannix2mo ago
tried html > svg instead ??
dys 🐙
dys 🐙2mo ago
I'm opening the SVG directly, so there's no html tag.
ἔρως
ἔρως2mo ago
if they cant be targetted, then you're sol you may be able to target based on the children of the svg, or based on location, but that's very "brittle" and breaks easily
Chris Bolson
Chris Bolson2mo ago
I must admit that I don't fully understand the use case. However, you could try something like using :not( ) and :where() to select the svgs which are not children of other elements:
svg:not(:where(div,section,header,main,footer,article,p,span, h1,h2,h3,h4,h5,h6) svg) {
background-color: #0008;
}
svg:not(:where(div,section,header,main,footer,article,p,span, h1,h2,h3,h4,h5,h6) svg) {
background-color: #0008;
}
Obviously you could limit or extend the parent selectors accordingly.
Want results from more Discord servers?
Add your server