feat: implement flexible pseudo element and pseudo class input#5546
feat: implement flexible pseudo element and pseudo class input#5546zehjotkah wants to merge 5 commits intowebstudio-is:mainfrom
Conversation
|
This can work for pseudo classes though there is a problem with pseudo elements which are actually children of selector they use. This means our style engine will compute values by cascade rather than inheritance. See for example Having pseudo element as state will compute as width: 10px; While in reality "before" would not have width inherited. The way it is rendered via parent class is already solved by descendant component. Only need to duplicate its logic for pseudo elements. |
|
@TrySound do you want pseudo elements being added only via the HTML tree and being attached only to HTML elements? I think a very useful feature of pseudo elements is to be attached to CSS classes/tokens. If I can only add a pseudo element via the HTML tree I couldn't do the above. Or do you mean that we should add the pseudo element via the token but display it also in the HTML tree? |
|
Its also about how psuedo element is:
So I agree token interface is a good fit, but you also need to solve:
You need both, tree and token menu. Tree node must be ephemeral, only created when pseudo element is selected from the menu. |
Pseudo-elements (like `::before`, `::after`, `::placeholder`) were incorrectly **cascading** properties from their parent element instead of **inheriting** them according to CSS specifications. This meant non-inherited properties like `width`, `height`, and `display` were incorrectly appearing on pseudo-elements.
|
Just my 2 cents: pseudo-elements are elements that can have their own styles, states and scripts attached to them — they are not a 'style'. Elements in Webstudio are displayed in the Navigator, and that is the most intuitive place to have them. The Style Editor - including tokens - are for managing CSS styles. It would be much more helpful for newbies to keep that distinction. |
|
@iocouto thanks for your input! You could also argue that in Webstudio HTML is "written" in the elements panel and CSS is "written" in the styles panel. Also pseudo elements are not actual nodes in the DOM. Because they don't exist in the DOM tree, you cannot assign them attributes like an ID. How would be the best way for you to attach a pseudo element to a CSS token in Webstudio? |
|
@zehjotkah I totally understand where you're coming from, but it's important for us to remember that when you say that "HTML is written in X, while CSS is written in Y", you're viewing your website building from the perspective of a PROGRAMMER: someone who already knows HTML & CSS, and who understands how HTML/CSS and pseudo-elements work. That is not necessarily the primary target audience of Webstudio: as you can see from the questions and support enquiries in the Discord server, there will be many, many users who are new to Web Development, and who view Webstudio as a way to 'design a website' rather than 'program a website'. Newbie Web Designers are not likely to be familiar with how we define pseudo-elements in CSS, and are unlikely to intuitively view pseudo-elements (such as 'placeholder') as part of a "style" definition. Intuitively, they will likely see them as separate elements in their own right, which they should be able to select in the Navigator and 'style' in the same way as other elements — eg., the same way they can select 'options' inside 'select' elements, or even 'bold' or 'span' elements inside a 'p'... |
|
I agree with @zehjotkah , the north star here is not what a newbe might think ( most newbies might never need to make use of it in the first place), its "who is the owner of that code" and who is "managing that code", pseudo element is owned by css, so its logical they should be found over style panel. Delete a token - pseudo element must be gone All these manipulations would be completely impossible without attaching pseudo element to the style source, where it physically lives in the actual real world CSS. Our north star has always been to never hide how things actually work. |
|
TBC in #5572 |


This PR replaces the limited "States" dropdown in the Style Panel with a flexible input field that supports any CSS selector, pseudo-class, or pseudo-element. This allows for advanced styling capabilities such as
:has(),:focus-visible, and complex combinators.Key Changes
Flexible Selector Input
:hover,::before,:has(:checked)).Enterkey).How to Test
:hoveror:first-childand press Enter.