Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix position: absolute element in a overflow: scroll element when scrolling

I want to accomplish a preview of an image gallery that is wider than the screen, using overflow: scroll (or auto). To the right, a shadow that overlaps the last visible image should indicate that more images are visible to the right.

Here is a Fiddle: http://jsfiddle.net/SBdLg/

First, I thought: Easy, give that image gallery a box-shadow: inset. But that will be shown behind the images. Now, with an overlapping div that has position: absolute, I reach the desired effect BUT the box-shadow also moves when scrolling to the right.

IMHO, this problem would also occur when using an image containing the shadow instead of the div on top.

Is the desired effect possible by CSS at all?

like image 360
k_haha Avatar asked Dec 20 '12 18:12

k_haha


People also ask

How do you scroll with an absolute position?

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 . container div, which has a fixed height.

What CSS position properties that stay in place even if you scroll up or down left or right?

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.

How do you position an absolute element?

Absolute An element with position: absolute is removed from the normal document flow. It is positioned automatically to the starting point (top-left corner) of its parent element. If it doesn't have any parent elements, then the initial document <html> will be its parent.


1 Answers

Removing position: relative from the outer DIV and positioning the shadow precisely where you need it (this is the ugly bit) will help you achieve this.

Check the demo: http://jsfiddle.net/SBdLg/11/

like image 110
techfoobar Avatar answered Nov 15 '22 05:11

techfoobar