Join the Webstudio community

Updated 7 months ago

How do you handle ::before and ::after on Webstudio?

At a glance

The community member needs to have a span with a background that can be animated, and they need to add content to this span. They provide an example from the Sanity.io website where the "content" heading has this effect. The community members discuss various approaches, such as adding an additional span inside the first one, or using pseudo-elements like ::before or ::after. However, they note that Webstudio does not support pseudo-elements, but they can achieve similar effects by adding additional instances and styling them. The discussion also touches on the challenges of implementing pseudo-elements in Webstudio, such as the differences in state cascade and inheritance, and the difficulty of accessing them from JavaScript. While the community members consider adding support for pseudo-elements, they ultimately decide that it's not a priority at the moment and they should focus on other tasks.

Useful resources
I need to have a span with a background to animate. So I'm making a background on a span but I have to add content on this.

Here is an example of what I'm doing to acheive : https://www.sanity.io/ (see the h1 heading on the word "content").

What is it the best way to do it on Webstudio? Not sure.

Thanks a lot!
1
B
M
J
34 comments
Can you just add additional span inside?
a span inside a span? I just don't know exactly how to handle ::before or ::after...
Webstudio do not support pseudo elements, but they are not necessary since you can always add instances and style them instead.
Drop text inside text and remove its text content
All right thanks. I gonna try!
@Milan Boisgard | Uncode School, I use pseudo element at work all the time. I have to switch thinking when using Webstudio. I've been able to do many things with an extra element and position absolute. That's how I now do background images, color overlays, gradients, etc.

I haven't found a case so far where I haven't been able to work around ::before or ::after. Maybe if I was doing some content: data attribute (I haven't needed that use case yet).
we should really add pseudo elements as well, I don't think its hard, @TrySound wdyt?
via a token state
It's not a state. It is descendent we don't want to support for all components yet.
I know its not a state, I am saying that the UI we have for states is basically the same that we could use for pseudo elements
you won't be able to select a pseudo elements on canvas directly anyways, only via its parent
Remember why we didn't go with states for content embed? Here's is the same.
can you explain?
State cascade and inheritance work differently
pseudo elements are normal elements, they just harder to access from js
So if you make it state, style panel will lie
I think they are impossible to access from js entirely
not the point
but given we know we are in a pseudo element state, we should be able to calculate using styles data mostlythe same way, maybe I am mising something
we won't have presets or anything like with actual tags
you set width on instance, go to ::before state. Is width set as remote?
kinda need to treat it like a special case
Just to be clear, width is not inherited style
It's not a special case, it is child instance
yes its special because we are selecting the parent but actually operating on a pseudo child
so special in the sense is that you aren't showing any more styles of the parent once you are in that pseudo element state
We already had this discussion about Descendent component
maybe we should not use the token state ui for this lol
not trivial, moving on
we could do it, but there are better things to do right now
Add a reply
Sign up and join the conversation on Discord