Position absolute wont scroll

The other week, I tried to use absolute positioning inside a container that had "overflow: auto" enabled. And, somewhat to my surprise, the absolutely-positioned elements were rendered relative to the overflow "viewport," not to the "natural bounding box" of the content.

This kind of threw me for a loop; and, it took me several days to come up with a solution. In retrospect, the solution is obvious. But, I had some weird mental block that was holding me back. All I had to do was wrap the content in non-overflow container and use said container as the anchor for positioning. To see what I mean, I've created a small demo in which I use the two approaches side-by-side. In the first approach, I'm using the overflow container as the position anchor.

Then, in the second approach, I'm wrapping the content in an extra container in order to provide a non-overflow position anchor:. As you can see, the main difference between the two approach lies in where the "position: relative" style is applied. In the first approach, the relative position is applied to the "overflow" container; and, in the second approach, it's being applied to the content wrapper.

Now, when we run this code, we get the following output:. As you can see, in the first approach, the four corner boxes are positioned relative to the overflow viewport. And, in the second approach, the four corner boxes are positioned relative to the inner content wrapper, which creates a more "intuitive" bounding box for the content.

ASIDE : If you try the demo, you'll see that in the first approach the absolutely-positioned corner boxes scroll with the content.

If you want the boxes to remain fixed in the corners, things get more complicated; especially in a context that may or may not present a scrollbar.

When possible, you should avoid a user experience UX in which fixed elements overlap with scrollable content. Aside from nav-bars, it's a difficult experience to get right. Looking back at this now, it seemed silly that this approach didn't occur to me immediately. But, at least I know now that I'll never forget it again.

How to Use Absolute & Fixed Custom Positioning in Elementor

It's not that hard to create a more fixed position like experience but you will need to change your html. If you can't move them for whatever reason, using js to move them for you is probably the simplest solution. Otherwise you would have to do things like detect scroll and update a"top" value on the fly which is way more prone to bugs and poor performance.

The problem with moving the absolutely-positioned elements to the viewport is that you run the risk of overlapping with the scrollbar itself unless you start to involve JavaScript detection in the matter.

At least, that's how I see it working. If they are inside the overflow area, then the absolute elements will naturally move horizontally when a scrollbar is introduced or removed.

However, if they are outside of the scrolling area, then you run the risk of "right:0px" overlapping with the scrollbar of the viewport. That's a tricky puzzle.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

I'm pretty happy with the way the design is turning out and everything seems to work, but now that my content is filling up the page I have realized that the page won't scroll, despite there being content below 'the fold'. I'm guessing this is because I'm using CSS tables with fixed positions.

I tried changing the position attribute to 'relative', and although this fixed the scrolling issue, it messed up the layout and I'm not sure how to make it work. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. Asked 6 years, 7 months ago.

This is a heading

Active 3 years, 9 months ago. Viewed 9k times. Jennifer Booth Jennifer Booth 13 1 1 silver badge 2 2 bronze badges. Why was this downvoted? Active Oldest Votes. That's easy pal, I've done it by myself using chrome developer tools. The problem is that you're using: "position: fixed;" on your divs. Using "position: absolute;" on every div, should work. Hope it helps you. This is correct. Here is a fiddle showing what happens when you change all of your position: fixed; to position: absolute; jsfiddle.

That fixed it. Thank you - you are my hero! DrydenLong that link is now broken. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.

Subscribe to RSS

Q2 Community Roadmap. The Unfriendly Robot: Automatically flagging unwelcoming comments. Featured on Meta. Community and Moderator guidelines for escalating issues via new responseā€¦. Feedback on Q2 Community Roadmap.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

The inner div takes up the full head of the container as desired. If I now add some other, flow, content to the container such as:. Aspernatur mollitia maxime facere quae cumque perferendis cum atque quia repellendus rerum eaque quod quibusdam incidunt blanditiis possimus temporibus reiciendis deserunt sequi eveniet necessitatibus maiores quas assumenda voluptate qui odio laboriosam totam repudiandae?

Doloremque dignissimos voluptatibus eveniet rem quasi minus ex cumque esse culpa cupiditate cum architecto! Facilis deleniti unde suscipit minima obcaecati vero ea soluta odio cupiditate placeat vitae nesciunt quis alias dolorum nemo sint facere. Deleniti itaque incidunt eligendi qui nemo corporis ducimus beatae consequatur est iusto dolorum consequuntur vero debitis saepe voluptatem impedit sint ea numquam quia voluptate quidem.

Then the container scrolls as desired, however the absolutely positioned element is no longer anchored to the bottom of the container but stops at the initial view-able bottom of the container. My question is; is there any way of having the absolutely positioned element be the complete scroll height of its container without using JS? You need to wrap the text in a div element and include the absolutely positioned element inside of it.

Setting the inner div's position to relative makes the absolutely position elements inside of it base their position and height on it rather than on the.

Without the inner, relatively positioned divthe. As an example, review my implementation of a fixed message area overlay populated programmatically :. When data becomes longer tha the sceen, mess keeps its position on the screen, while data scrolls under it. So gaiour is right, but if you're looking for a full height item that doesn't scroll with the content, but is actually the height of the container, here's the fix.

I ran into this situation and creating an extra div was impractical. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. Asked 6 years, 9 months ago. Active 1 month ago. Viewed k times. Tha'er M. Al-Ajlouni 5, 7 7 gold badges 27 27 silver badges 34 34 bronze badges. Chris Meek Chris Meek 4, 5 5 gold badges 30 30 silver badges 40 40 bronze badges. If you remove top: 0; it simply does not work anymore.

Without JS to calc innerHeightthat will be hard. Active Oldest Votes. Yaron U. The fill-height element is clearly scrolling with the content, didn't the OP want it anchored? By changing the blue background to a background image, you can see what I mean when I say that it's not anchored jsfiddle. Fixed positioning will position the element relative to the browser, which may not be the desired result.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm really not sure what to try, since this is specific to Internet Explorer.

Been trying different things with the code over the past couple of hours with no luck so far.

position absolute wont scroll

Replace that with this:. And that's where IE is placing it, relative to the entire page. It's doing what you're telling it to do. With the other browsers, it's position is absolute compared to that header.

But to take a guess, you probably wanted to set it to position: relative. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. Absolute positioning error in Internet Explorer 11 Ask Question. Asked 4 years, 10 months ago. Active 3 years ago. Viewed 54k times. Sherwin Flight Sherwin Flight 2, 5 5 gold badges 27 27 silver badges 51 51 bronze badges. Did you try adding position: relative; to.

Adding position:relative to page-content, and one other container, solved the problem. Rooster, since you commented first if you post it as an answer I'll accept it. Thank you both for your help, I also up-voted both of your comments. Active Oldest Votes. Rooster Rooster 8, 7 7 gold badges 32 32 silver badges 68 68 bronze badges. Thanks for the help. And yeah, it was just IE Looks like this might have fixed a problem I had.

By implementing the above, all three are now consistent in their wrong but easily fixable alignment! Replace that with this: position:absolute; top:0; bottom:0; left:0; right:0; Anyway, you've set corner to position: absolute; top: 20px; left: px; And that's where IE is placing it, relative to the entire page. Just in case this helps someone else: I had a similar issue. It looked like ie11 was ignoring the 'right' property: right: px; but it turned out to be because I had set the 'left' property to: left: initial; Turns out the 'initial' keyword is unsupported by ie left: initial doesn't work in internet explorer.

Sign up or log in Sign up using Google.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Learn more. Asked 5 years, 11 months ago. Active 5 years, 11 months ago. Viewed 14k times. I need to put an absolute div in the bottom right of a page.

This is what I want to get:.

position absolute wont scroll

Tobia Tobia 6, 24 24 gold badges 81 81 silver badges bronze badges. Use fixed or static instead of absolute. Alien May 7 '14 at Active Oldest Votes. If I add margin-bottom into. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.

Post as a guest Name. Email Required, but never shown. The Overflow Blog. The Overflow How many jobs can be done at home? Featured on Meta. Community and Moderator guidelines for escalating issues via new responseā€¦.

position absolute wont scroll

Feedback on Q2 Community Roadmap. Technical site integration observational experiment live on Stack Overflow. Triage needs to be fixed urgently, and users need to be notified uponā€¦.

Dark Mode Beta - help us root out low-contrast and un-converted bits. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. How are we doing? Please help us improve Stack Overflow. Take our short survey. Learn more. Asked 5 years, 11 months ago. Active 5 years, 11 months ago. Viewed 14k times. I need to put an absolute div in the bottom right of a page. This is what I want to get:. Tobia Tobia 6, 24 24 gold badges 81 81 silver badges bronze badges. Use fixed or static instead of absolute.

Alien May 7 '14 at Active Oldest Votes. If I add margin-bottom into. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Q2 Community Roadmap. The Unfriendly Robot: Automatically flagging unwelcoming comments.

Featured on Meta.Learn Development at Frontend Masters. A reader sent me in a GIF showing off a cool effect they saw on Google on mobile. Presumably the homepage you see when you launch Chrome on Android? OH: I'm a mobile web developer, so I basically spend all day getting requests for content to stick to the top after some scrolling.

Little choppy, but the idea is there:. All we do is think of and design for the two different possible states:. We toggle between them simply by changing a class name. There is no trickery with having two search forms that reveal themselves in different scenarios. Much easier to just move a single one around. The trick here is applying that class at just the right moment.

In our little demo, we can just test for when that perfect moment would be and hard code that into some JavaScript watching for scrolling. If the page has scrolled down pixels or more, it will have that class applied.

Even if you go down and come back up the class will go away because this little function gets called on every scroll event. This is the kind of thing that would be sweet to do in CSS alone. Note that this demo relies on fixed positioning, which has a sketchy history on mobile. Some reading:. There are a lot of magic numbers in this demo. Anytime you are setting heights there should be some warning flags happening up in your brain. In this demo, if that centered image in the header changed height, it would look weird pretty much no matter what.

Even if you fixed the header to look right after a change, the JavaScript has corresponding magic numbers for when to change state. Perhaps some version of using waypoints or the concept of it could make a more bulletproof system.

Frontend Masters is the best place to get it. On iOS 7 and less yep, the event is only triggered at the end of the scroll. Not on Chrome for Android, and not on iOS 8 have to test for the last one. Remy has a couple of good functions for debouncing and throttlingthe latter is useful for resizing for example.

Here is the link. Worked very well on iOS7, but not on iOS6. Looks good. Three-State Version. I like it. Forked you : same idea, but with an intermediate top position so I could ease the transition to its fixed position.

Likewise with the top bar background color. Great post Chris. One variation I noticed on the Android Chrome browser was that once the window is scrolled up at all, the search bar fades then jumps to the top.

I might play with your code a bit to recreate this effect. Love the page! There are lots of websites out there using scroll-detection Javascript for purely decorative effects that should be in CSS, or for performance goals like lazy loading.


thoughts on “Position absolute wont scroll”

Leave a Reply

Your email address will not be published. Required fields are marked *