Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop absolute div from overflowing from parent?

Tags:

html

css

layout

I have a long div inside a parent.

I think it needs to be absolutely positioned because I want to to scroll horizontally.

However I only want the section inside the parent div to be visible. I thought setting overflow: hidden on the parent would achieve this, however no such luck....

See this js fiddle for an example.

Does anyone know how to get this effect?

Thanks

like image 547
Chris Avatar asked Feb 22 '23 22:02

Chris


1 Answers

You should set the parent (box1) to position:relative; Otherwise the box2 gets positioned relative to the body and gets outside the flow of box1.

Editted example

like image 81
MarkSmits Avatar answered Feb 24 '23 12:02

MarkSmits