Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Overflow - Not working as expected

Tags:

html

css

overflow

http://jsfiddle.net/bSnaG/

In my mind the above example should look like a grey box with #x not going past the edge and #y poking out the bottom.

But it's not like that - apparently setting overflow-x: hidden; causes overflow-y: scroll | auto;.

Is there any way around this?
I need to allow certain elements to escape the bounding box without setting overflow: visible on #box.

like image 872
Sam Avatar asked Nov 11 '10 10:11

Sam


People also ask

How to fix overflow issues CSS?

To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.

How overflow works CSS?

The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area. The overflow property has the following values: visible - Default. The overflow is not clipped.


2 Answers

#y can't break out of its bounding box without being taken out of the flow of the document. Does adding position: absolute; to #y give the effect you're after?

Update

Restructured HTML example, including a containing box to allow everything to be easily positioned together. Try it out here: http://jsfiddle.net/GfNbp

<div id="container">
    <div id="box">
        <div id="x"></div>
    </div>
    <div id="y"></div>
</div>


#box {
    width: 100px;
    height: 100px;
    margin: 10px;
    background: #ededed;
    padding: 10px;

    /* ADD THE OVERFLOW */
    overflow-x: hidden;
    overflow-y: visible;
}

#container{
    position: absolute;
    top: 30px;
    left: 20px;
}

#x {
    width: 150px;
    height: 10px;
    background: #c1ffb2;
}

#y {
    width: 10px;
    height: 150px;
    background: #c4b2ff;
    position: absolute;
    left: 20px; /* margin+padding */
    top: 30px; /* margin+padding+x-height */
}
like image 71
batwad Avatar answered Oct 07 '22 01:10

batwad


Here's what I have, and it works:

#box {
    position:absolute;
    width: 100px;
    height: 100px;
    margin: 10px;
    background: #ededed;
    padding: 10px;

    /* ADD THE OVERFLOW */
    overflow-y:visible;
    overflow-x:hidden;

}

#x {
    width: 150px;
    height: 10px;
    background: #c1ffb2;
}


#y {
    width: 10px;
    height: 150px;
    background: #c4b2ff;
    position: fixed;
}
like image 38
Bryan A Avatar answered Oct 07 '22 01:10

Bryan A