Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute position and Overflow:hidden

Tags:

html

css

<div id="parent" style="overflow:hidden; position:relative;">   <div id="child" style="position:absolute;">   </div> </div> 

I need to show child element which is bigger than it's parent element, but without removing overflow:hidden; is this possible? parent element has position:relative; child element gets stripped as soon as it's out of it's parents borders.

(elements have additional css defined I just put style attributes for clearness)

like image 811
Headshota Avatar asked Apr 01 '11 12:04

Headshota


People also ask

How do you hide overflow in absolute?

Try adding position: relative to your outer div. This will position the image relative to that div (honoring the overflow style) instead of relative to the page.

Why does overflow hidden not work?

It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.

What is overflow hidden in CSS?

With the hidden value, the overflow is clipped, and the rest of the content is hidden: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.

What is the opposite of overflow hidden?

The opposite of the default visible is hidden. This literally hides any content that extends beyond the box. This is particularly useful in use with dynamic content and the possibility of an overflow causing serious layout problems.


1 Answers

It's completely impossible to do what you want with both overflow: hidden and position: relative on the parent div.. instead you can introduce an extra child div and move overflow: hidden to that.

See: http://jsfiddle.net/thirtydot/TFTnU/

HTML:

<div id="parent">     <div id="hideOverflow">         <div style="width:1000px;background:#ccc">sdfsd</div>     </div>   <div id="child">overflow "visible"</div> </div> 

CSS:

#parent {     position:relative;     background:red;     width:100px;     height:100px } #child {     position:absolute;     background:#f0f;     width:300px;     bottom: 0;     left: 0 } #hideOverflow {     overflow: hidden } 

#parent {   position: relative;   background: red;   width: 100px;   height: 100px }  #child {   position: absolute;   background: #f0f;   width: 300px;   bottom: 0;   left: 0 }  #hideOverflow {   overflow: hidden }
<div id="parent">   <div id="hideOverflow">     <div style="width:1000px;background:#ccc">sdfsd</div>   </div>   <div id="child">overflow "visible"</div> </div>
like image 189
thirtydot Avatar answered Oct 11 '22 02:10

thirtydot