-
Notifications
You must be signed in to change notification settings - Fork 693
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
[css3 positioning] support position:sticky inside an overflow:hidden|auto on general parents #865
Comments
mozbugzilla link : https://bugzilla.mozilla.org/show_bug.cgi?id=1329203 |
maybe not really a bug but by implementation. Check this specs out http://www.coreyford.name/files/position-sticky-presentation/
|
The official spec for position: sticky is at W3C and there is no mention of |
This spec seems to have changed quite a bit since the implementation in Gecko. It no longer mentions scrolling ancestors, it exclusively talks about containing blocks now. I agree that the current writing of the spec would allow crossing overflow:hidden / auto descendants when computing the offset. But I don't know what the rationale behind that change to the spec was, or whether implementing that change is web compatible. |
+1, I find this a very strange limitation especially when the element in question is not actually hidden. It makes it much more fragile to use it given that a change to a parent container / component could break sticky behaviour entirely |
It would be nice to make this work: <div class="table-wrapper">
<table>
<tr><th>Foo</th><th>Bar</th></tr>
<tr><td>sin</td><td>cos</td></tr>
<tr><td>tan</td><td>baz</td></tr>
...
</table>
</div> .table-wrapper {
overflow-x: auto;
}
th {
position: sticky;
top: 0;
} I need both horizontal scrolling and sticky header. |
I'm building a table template in SCSS which requires this functionality in many situations. Thankfully, everything now works in Chrome [63], Edge [41], Firefox [59] and Safari [11]. Here's a basic test case for overflow-x and overflow-y support: |
@SimplyPhy was going to comment and say safari just needed prefix for sticky, but now I see you updated your comment. Though safari still has an issue 'sticking' your |
Yup, thanks @jonjohnjohnson and nice find. |
I have the following rule: html, body {
overflow-x: hidden;
} and because of it, I'm not able to use |
@natematykiewicz though not ideal, I believe all current browser versions support sticky behavior if you alter your DOM structure so that the scrolling element is inside the body/html, filling out the screen. This does make it so browsers that resize the viewport on scrolling of the |
@jonjohnjohnson my previous comment was that I have |
The computed values of both
This is what causes our issue and is spec compliant. Furthermore, check your "(but not BOTH)" solution in safari, including iOS, because that approach hasn't historically given people what they have sought out. -> overflow-xhidden-doesnt-prevent-content-from-overflowing.... Again, the most robust solution is to scroll an element WITHIN the body, not the body/html/document. Good luck. |
Just wanted to make a note for others about how allowing general Also, when we (eventually) have |
@SimplyPhy in your codepen (https://codepen.io/SimplyPhy/pen/oEZKZo ) on the table,Is there any way to restrict the scroll on header content. Scroll looks odd on the header. |
For anybody stumbling upon this issue via google, here's a workaround (at least for my case) using a polyfill: https://stackoverflow.com/a/52420677/4903358 |
For my use case, one of the ancestors in the DOM had The way I fixed it was removing body {
overflow-x: hidden;
} |
@protoEvangelion I realized after trying that the solution does not work on mobile browsers :( |
@damienroche I believe androids webview behaves according to spec here, but it's iOS that doesn't. If you want to chip in and voice concern about their noncompliance here's the public ticket. WebKit Bugzilla - Bug 153852 - with overflow:hidden CSS is scrollable on iOS |
Anyway, it's incredibly unfortunate that setting |
OK, @tabatkins and I filed a new issue about having an element be sticky to multiple scrollports: #8286 As far as we can tell, the rest of this issue should be handled by appropriate use of either |
@fantasai confirmed! The discussion in this issue has become so broad that it's hard for newcomers to easily understand which aspects are and are not outstanding. |
The only thing that helped for my detection |
I concur |
Hey, just commenting since we have a similar situation as @AaronBeaudoin brought up in #865 (comment) but with some extra nuance that makes Big edit: It turns out I'm just wrong about
We're taking advantage of basically this ![]() But in practice we aren't able to use ![]() It seems like the only workable solution here is to set We could position the tooltips with JavaScript and separate them outright from the main page layout tree, but it's such a janky solution. Placement in the HTML tree, statically generated, and positioned relatively to a parent |
@towerofnix unfortunate that that's not the case, I actually ran in to similar situation recently, though not related to |
I would say, that for 95% of the usecases that run into this, they would be fine falling back onto using the window for placement. Perhaps just a "sticky-window" or something like that additional, could solve the issue, but not open the need to select the anhoring ansestor. You would just get your parent, or the window. And if you choose the window, things like overflow and the ancestors scroll position is not longer taken into account, cause it can just be relative to the window. |
While I did not find a working solution to keep both overflow and sticky feature, I explored the possibility to disable overflow only when working with sticky elements. The following piece of code resets the overflow property of elements that have a child marked with the sticky class.
I'm used to working with the bootstrap framework, so I based my css selector on the .sticky-top and .sticky-bottom classes, but feel free to change it to your needs. Also, I read that the sticky feature would only cause troubles with parents that have overflow with no fixed width or height set. So I explored further the possibility to disable only these elements.
This requires the width and height attributes to be set on the elements and not via classes (quite common)... so I admit that this attempt may be worthless but might give you some ideas. Let me know if I'm heading wrong way ;) |
css3 position
Currently the position:sticky element exclusively works when the all of general parents are overflow:visible. This is problematic a little whilst we use overflow:hidden trick for clearfix etc.
Testcase attached. Here is a simplesample, how is the layout broken when we change the overflow to visible, however sticky starts to work in that case. I detected, all of general parent-elements in the parent-path must be overflow: visible, which is weird a little. Any overflow:hidden in the parent-path kills the sticky.
ER: sync somehow the spec to allow sticky subcontainers inside a overflow:hidden general parent.
testcase: https://jsfiddle.net/utasir/rmmkxq62/11/
The text was updated successfully, but these errors were encountered: