Select a pseudo-element's "owner" (css nesting)
Hey! I just wanted to know, when nested in some pseudo-elements rule, is it possible to access its "owner" (select #owner:hover::after when in #owner::after, for instance)? That's more a question about CSS than a problem, I'm just curious.
17 Replies
Maybe with
:has(::after)
?It doesn't work, actually I don't think it's possible
I think I’ve seen on a KP video that you can’t select that way at least in scss if I remember right.
Guess I'd just stick with that then
I'm waiting till tomorrow to mark this as solved, just in case
yea, this is the way. can't get out of a nest looking up
If it were just a direct child of the #element,
:hover > &
would've worked, I was wondering if there was a way to do that with pseudo-elements, but coming up with that wasn't a problemyea, i know, but with pseudo's unfortunatly not
Anyway thank y'all guys
Yea
good luck
Should I close the post?
just add the solved tag
Okay
are you working with css or sass/scss?
if you're working with scss, it's actually possible to do what you want
however, i VERY STRONGLY recommend that you do not do it, as the code becomes a convoluted mess
an alternative could be to do this:
i do use the selectors like this, but only when i have styles to apply to
:hover
, which you often do
this way, you can also easily re-use the :hover
to, for example, style a child element, like this:
and if someone says "butt muh 80 chars colms", i will roll my eyes as 80 columns of text hasnt been a problem since 1280x1080 was invented
(just don't over-do it)I never used scss, and again I was just curious about it being possible.
Anyway, thanks for the answers :D
the examples i gave also work in css
What? I thought you were saying there was a really hacky or just "bad" way to do it in scss (directly nested in
#element::after
), and that you just preferred to give an alternative in css xdyes, but i didn't share that cursed horrible thing here