-
Notifications
You must be signed in to change notification settings - Fork 685
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
[selectors-5] Proposal for pseudo-selector :overflowed-content #2011
Comments
I'm afraid this could cause circular definitions like :not(:wrapped-line) {
height: 0;
} |
@Loirooriol, any suggestions? The same probably could say for |
|
@Loirooriol then lets define it as "pseudo-element :wrapped-line"? Would it help? |
But then I don't think this pseudo-element would be useful. You wouldn't be able to use it to target an element if it has wrapped content/text, which is what you wanted. |
@Loirooriol What about specifying in media-query like |
Media queries currently would not work, because their conditions cannot depend on individual elements. Element queries are what would be necessary. They are Edit: Recently, Tantek Çelik has rekindled discussion about standardizing element queries / container queries in the RICG, asking whether to try doing so in the WICG; see WICG/cq-usecases#44. |
Element queries aren't magical either; they're limited to a few bits of layout information, and have some important restrictions that make this information possible to obtain without circularity (for example, the "container" being queried for its size has to have |
@tabatkins are you saying |
I'm saying it's circular, for the reasons given by others earlier. I was just explaining that EQs, while superficially circular, have some restrictions that let them dodge the circularity if they're carefully designed; |
Haha no they're not. What have they done in the last 2-3 years? I see no activity at all that would indicate the RICG is even still alive. During that time I have written what I believe to be the only element query spec that contains new syntax ideas which was based on the features of the EQCSS syntax and plugin. We included a 'lines' feature, but of all of the features it's the least reliable element-based breakpoint, and it was a real challenge to calculate! After being able to experiment with the On the other hand, I believe I have a demo (using EQCSS) that illustrates exactly what you seem to be describe wanting to be able to do: https://codepen.io/tomhodgins/pen/KNywpV .widget {
width: 500px;
height: 500px;
margin: 0 auto 2em auto;
border: 5px solid red;
text-align: center;
position: relative;
}
h2 {
width: 100%;
font-size: 50pt;
margin: 0;
line-height: 1.2;
}
@element .widget h2 {
eval('offsetHeight <= parentNode.offsetHeight && "$this"') {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
eval('offsetHeight >= parentNode.offsetHeight && "$parent"') {
overflow: auto;
overflow-y: scroll;
border-color: lime;
}
} So what's interesting to note here, is that even though EQCSS has a Here's a rebuild of my EQCSS-powered demo using HTML, CSS (with CSS variables), and JS — I think a solution like this is what you're looking for and thankfully it doesn't require CSS to be extended beyond what it's already capable of doing today :D <div class=widget>
<h2>Example</h2>
</div>
<div class=widget>
<h2>Example sentence that's not too long</h2>
</div>
<div class=widget>
<h2>This is an example sentence that's too long to be displayed centred, so it needs to scroll inside the parent element and be positioned normally.</h2>
</div>
<style>
.widget {
width: 500px;
height: 500px;
margin: 0 auto 2em auto;
border: 5px solid red;
text-align: center;
position: relative;
overflow: var(--overflow);
overflow-y: var(--overflow-y);
border-color: var(--border-color);
}
h2 {
width: 100%;
font-size: 50pt;
margin: 0;
line-height: 1.2;
position: var(--position);
top: var(--top);
transform: var(--transform);
}
</style>
<script>
function OverflowOrCentered() {
var widget = document.querySelectorAll('.widget')
for (var i=0; i<widget.length; i++) {
var headline = widget[i].querySelector('h2')
if (headline.offsetHeight <= widget[i].offsetHeight) {
headline.style.setProperty('--position', 'absolute')
headline.style.setProperty('--top', '50%')
headline.style.setProperty('--transform', 'translateY(-50%)')
} else {
headline.style.setProperty('--position', '')
headline.style.setProperty('--top', '')
headline.style.setProperty('--transform', '')
}
if (headline.offsetHeight >= widget[i].offsetHeight) {
widget[i].style.setProperty('--overflow', 'auto')
widget[i].style.setProperty('--overflow-y', 'scroll')
widget[i].style.setProperty('--border-color', 'lime')
} else {
widget[i].style.setProperty('--overflow', '')
widget[i].style.setProperty('--overflow-y', '')
widget[i].style.setProperty('--border-color', '')
}
}
}
window.addEventListener('load', OverflowOrCentered)
</script> |
@tomhodgins, with testcase https://output.jsbin.com/rawezas/5/quiet
|
Perhaps would want to know if cropped horizontally or vertically - |
Ah okay, so you're thinking more horizontally then :D I've got a demo of 'overflow shadows' that make use of
It should be possible to 'translate' my EQCSS demo here to native HTML + CSS + JS in the same way I did for the last demo. Would this be something that applied only to individual elements, or would it apply to elements containing child HTML elements as well? In this example I'm working with 2 elements (rather than one) in order to measure something that's cut off, but it makes me wonder if we need something like:
Where |
I am changing it to After more thinking, I was thinking only about |
and next one:
Elements with display:none cannot be focusable. IE, FF and Cr differently handle this stylesheet. |
@Nadya678 That's an interesting testcase, which may be worth discussing in another issue, possibly with whatwg people. I think the trick is that an element must have a box in order to be focusable, but once it has become focused, this restriction does not need to hold. That is, focused elements don't need to continue been focusable. This is how Firefox and Edge seem to behave. Alternatively, Chrome seems to think that if a focused element stops being focusable, it should no longer be focused. But this does not imply that, if later the element becomes focusable, it will automatically become focused again. In neither interpretation there is a circularity, unlike the proposed |
@Loirooriol notice I changed the recommendation to |
I do not see any approach for this that would break the circularity discussed above. Yes, it is unfortunate that CSS has this architectural limitation, but it does have it, and selectors cannot switch between matching or not matching depending on the result of layout. This isn't a matter of cleverly playing with the syntax, it is a matter of what this means. In the general model of how CSS works, this does not make sense. I am afraid the only thing we can do here is to close as WONTFIX. |
@frivoal why not to improve CSS capability and change the way it works? I think otherwise will continue over years to popup such questions, like EQCSS. This proposal I drafted many years ago, didn't had time (and good place) to post it. |
If the question is "why can't we add this selector?" the answer is "because that's not how browsers work". If the question is "why don't we change how browsers work", we're going to need a separate discussion, and very substantive supporting arguments. I am not familiar ith EQCSS. Maybe it is a good proposal, and presenting it to browser vendors and the CSSWG could be a worthy endeavor, if you think it is possible to implement at reasonable cost and solves a sufficiently important problem (there's a balance between these two things). Please open a separate issue about that if you want to pursue it. Either way, this issue is not about EQCSS or some other way of overhauling browser architecture. It is about "can we have :overflowed-content?" And the answer, given the current state of browser architecture is that no, we cannot. |
Can't you use an IntersectionObserver instead? https://jsfiddle.net/f2gp7pnq/ new IntersectionObserver(function([{intersectionRatio}]) {
root.classList.toggle('overflowed-content', intersectionRatio < 1);
}, {root}).observe(root.lastElementChild); |
@Loirooriol technically is possible everything. I posted here a propose for CSS. And @frivoal fyi EQCSS has been proposed multiple CSS solutions, and I think it is in work of progress; you can ask more to @tabatkins. |
Exactly. |
@Nadya678 @Loirooriol input:hover {
height: 0;
width: 0;
} And we live with this for many years, without any real problems... |
Here is a case which needs overflow as condition, consider the case that we has some elements position at right, and we need to keep those elements has same visual position at non-overflow and overflow case: .container {
padding-right: 40px; // non-overflow case, padding right 40px
} |--------------------------------------------------------------------------------------------------------|
| |
| _______________________________________________ |
| | This is a search box. 🔍 | |
| |----------------------------------------------| |
| |
| |
| |
| |
| |
| |
| |
|--------------------------------------------------------------------------------------------------------| .container :overflow-y {
padding-right: 30px; // overflow-y case, vertical scroll bar takes up 10px space,
// adjust the padding to keep align with non-overflow case.
} |--------------------------------------------------------------------------------------------------------|
| |
| _______________________________________________ |
| | This is a search box. 🔍 | |
| |----------------------------------------------| |
| | |
| | |
| | |
| | |
| | |
| |
| |
|--------------------------------------------------------------------------------------------------------| |
As was stated earlier in the the thread by me and Florian, we recognize that this would be a useful capability, but it's also fundamentally impossible to square away with the Selectors+properties model; it's intrinsically circular (you can use the pseudoclass to apply styles that make the pseudoclass no longer apply), and so can't reasonably be worked around. Seemingly-similar cases, like Element Queries or the :hover pseudoclass, actually have important distinctions that allow us, with effort, to break the circularity and allow them into the language. This is not true for an overflowing pseudoclass. I'm going to close this issue, as there's nothing further that can be productively said. |
Currently there are no specs to target if element has wrapped content/text (outside the
overflow:hidden
area). It could be usable for example to decide if to show customized tooltip, apply special style, show dropdown, and probably more usecases.Landing multiple line wrapping proposal #390 would make this even more actual
, could specify it with.:wrapped-line(n)
like:wrapped-line(3)
For an example here is a CSS menu hack to decide if to show dropdown with wrapped elements http://kizu.ru/fun/chevron/, perhaps
:wrapped-line
could simplify things.Update: Is changed to :overflowed-content [:overflowed-content-x, :overflowed-content-y]
The text was updated successfully, but these errors were encountered: