-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Add wrapper pseudo element #588
Comments
If you support this proposal, please reply so that we can get more people involved and underline the importance of |
The most important part of this proposal is that it allows to get rid of wrapper HTML elements, which are only used for layout purposes. An example for this can be seen on this very GitHub page, which currently has a structure like this: <div id="discussion_bucket" class="clearfix">
<div class="discussion-sidebar js-sticky is-stuck" style="position: sticky;">
…
</div>
<div class="discussion-timeline js-quote-selection-container ">
…
</div>
</div> With this pseudo-element it would be possible to replace the outer #show_issue::wrap(:first-child, :last-child) {
display: block;
}
#show_issue::wrap(:first-child, :last-child)::before {
content: "";
display: table;
}
#show_issue::wrap(:first-child, :last-child)::after {
clear: both;
content: "";
display: table;
} Note: This example also requires stacking of pseudo-elements. Though even without pseudo-element stacking there are use cases for a wrapper pseudo-element. For reference, this proposal was previously discussed on www-style. Sebastian PS: @Ian-Y, please change the summary to "Add wrapper pseudo element" to be more general (and remove [css3-selector], as Selectors Level 3 is already a recommendation). This may rather be part of the CSS Pseudo-Elements Module. |
@SebastianZ Thank you for the example of use case. And I had changed the thread title as per your suggestion. |
Here are some older discussions about this:
I skimmed through them and saw three counter proposals: Use tags for the start and end elementsIdeaTag the start and end elements via ExampleDL.example > DT {group-open: myGroupName; }
DL.example > DD {group-close: myGroupName; }
/* Show green border around each `DT`/`DD` group. */
::group(myGroupName) {
border: 2px solid #0d0;
} Use decoratorsIdeaIntroduce an @FremyCompany mentioned this in '[css4-pseudo] The need for more powerful pseudo elements', which was obviously inspired by an old version of the Web Components spec. Example@decorator video {
content: contents slot(icon) slot(text);
@slot(icon) { content: ' V'; font-family: ...; }
@slot(text) { content: ' video'; }
}
@decorator fog {
content: slot(wrapper);
@slot(wrapper) {
content: contents slot(overlay);
position: relative;
}
@slot(overlay) {
position: absolute; top...;
background: rgba(...);
}
}
@decorator only-first-image {
content: contents(img:first-of-type);
} Use a pseudo-classIdeaIntroduce a This is obviously restricted to some specific use case and was proposed by Leif Halvard Silli in 'A *:body pseudo class'. He didn't provide a proper example of how he imagined the pseudo-class to work, though as he's talking about something that "encapsulates the entire "body text"", I assume he mixed up the use cases of pseudo-classes and pseudo-elements. Sebastian |
Some important comments from the related www-style thread:
|
As I and @fantasai stated in the email thread, implementors have historically been strongly against this sort of functionality; it makes for a very complicated implementation, apparently. Features don't really do well without implementor interest, and in this case we have clear implementor anti-interest, which is a strong signal that we should not add the feature to a spec, as it will not be successful. See https://wiki.whatwg.org/wiki/FAQ#Is_there_a_process_for_adding_new_features_to_a_specification.3F for a rough idea of how adding new features work. Author interest is one part of the process, but not all of it! |
Everybody agrees that the |
It's very possible for something to be WONTFIX in both languages! But also, Hixie hasn't been the editor of HTML for a while now. This could possibly be relitigated in WHATWG; Domenic and Anne may have different opinions now. (And I'm happy to support reusing |
I came across this discussion after resorting to researching to see if a css pseudo wrapper element had miraculously been implemented after years of having to add wrapper divs to my designs for purely stylistic and layout reasons. I wanted to add one of my biggest use cases for having to use wrappers and that is to support gutters in CSS with responsive designs. A technique which is used often is to add an inner wrapper to a container and apply a negative margin to it so that top and right margins can be added to it's children to simulate guttering between elements. It has to be done this way because if the order of the elements change (i.e. using media queries) or there are more than one row of elements then the margin must be applied to every child element and cannot be achieved using the Therefore using wrappers is the most flexible and effective way to overcome these layout issues with respect to managing spacing between elements in layouts. Yet having to use wrapper divs creates so much chaos with regards to managing CSS as they mess with the hierarchy of the DOM and CSS specifity becomes a real nightmare. It makes it almost impossible to reliably and consistently style other elements inside wrapper divs especially when working on large teams made up of members of different skill levels. I think that because the need for responsive sites and apps is growing, it is becoming even more paramount that we ease the burden of authoring HTML, instead of forcing developers and front-end designers to add wrapper divs where CSS falls short. |
Adding a use case here, I can only strongly echo that the rationale for this is to separate the semantic content in HTML and presentational concerns in CSS. Quite simply, take a basic webpage where you have many Pending that, is there any way we can bridge the gap to implementers, maybe some are around here, and reconcile our differences maybe? If we deem this as a desirable spec, then the thing that's left to do is only to figure out how to feasibly implement it 😉 |
I've had a bunch of people ask me about a <ul>
<li>item
<li class=target>target
<li>item And you do something like this: .target::wrap {} How does CSS see your HTML? Does a selector like Can anybody explain how it would work? What happens to event listeners on wrapped elements? Does the wrapper respond to things like If the desire is for more layout control, are there better ways this layout ability could be used without relying on using CSS to fake HTML in order to accomplish it? |
@tomhodgins I would expect it act just like styling the Shadow DOM works in that it would be invisible and other CSS pseudo selectors would ignore any faux elements represented by CSS selectors, just like I would expect .target::wrap {} to only exist for the sake of styling the element it has selected. |
Yeah, pseudo-elements don't change the DOM structure; Selectors only looks at the DOM structure for the purpose of matching. I'll note that the use-case of "grouping dt/dd" has now been solved - HTML just allows |
The way how the feature is done unfortunately makes it very limited: multiple nested Also, please don’t forget that CSS-based wrappers could be dynamically changed depending on e.g. media queries which is impossible with hard-coded HTML wrappers. |
My use case would be supporting responsive iframes, for which the only solution currently is to have a wrapper element with height: 0 and padding-top: 0.5625% or whatever proportion is required: iframe.responsive::wrap {
display: block;
height: 0;
padding-top: 0.5625%;
position: relative;
overflow: hidden;
}
iframe.responsive {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
} |
Issue #2406 is about a different but related proposal, which seems much more likely to gain acceptance, as it is significantly easier to implement. People who like this proposal should consider who well that one would serve their needs, and get behind that if it works for you. |
I was trying to see how far I could get with avoiding wrapping elements to achieve sections as full-width bands. There are some exciting CSS things being discussed: * A [::wrapper pseudo element](w3c/csswg-drafts#588) seems stalled because it could cause some tricky situations in the DOM, but * A [::contents pseudo element](w3c/csswg-drafts#2406) is still under consideration and has some steam.
Please find the information of
::wrap
pseudo element through this hyperlink.There are abundant use cases of this pseudo element. For example, because there has been no wrapper element for wrapping
<dt>
and<dd>
pairs in description list<dl>
, web developers have been having no choice but to resort to JavaScript to insert<li role="presentation"></li>
into<dl>
or even use less semantic list elements like<ul>
. Yet another example is that layout designs such as "left and right columns" is everywhere so we have been having to add extra wrapper<div>
s into HTML for that kind of purpose.The aforementioned examples are just a tip of iceberg. The use cases of
::wrap
are a lot more than the use cases of:first-child
,:empty
, etc.Could we please have this
::wrap
pseudo element be formally adopted? With this pseudo element, web developers would be able to write more semantic HTML and no longer have to resort to JavaScript, which can result in the unwanted FOUC. From the aspect of use case, there seems to be no reason why this pseudo element should not be adopted.The text was updated successfully, but these errors were encountered: