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?
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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With