8

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.

2
  • I can't come up with a solution using the markup you posted, but if you tell us more about what you need we might be able to suggest an alternative? Commented Nov 17, 2010 at 16:42
  • More detail is needed, what is the exact behavior/context of the items in the box and under which conditions do they get bound or hidden? Commented Nov 18, 2010 at 1:08

3 Answers 3

14
+50

#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 */
}
Sign up to request clarification or add additional context in comments.

6 Comments

As a proof of concept it works, but I still need #y to be relative to #box
Then add position: relative; to the #box
That won't work as it's not taking #y out of context. It has the same effect as not adding position: absolute. Thanks for your answers!
It sounds like the structure of your HTML is wrong then, and you don't actually want #y to be a child of #box as you don't want it to be bound by it in any way, just positioned next to it. Take it outside of the box (ha ha) and it's a simple case of positioning.
It's kind of strange but just adding position:absolute to #y makes it work on Chrome 7. Since you said it needs to be relative to #box, does #box have any special positioning? As far as I tried, if you leave it on default, it works.
|
1

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;
}

4 Comments

Doesn't look like you need to position #box absolutely either.
That will only work as long as the page itself doesn't scroll. Try adding body { height: 1000px; } to the example.
Have you tried using a different methodology? Perhaps using a vertically-tiled graphic in an offset div layered above the #box div or something along those lines?
position: fixed; makes the block relative to viewport; not what OP wants.
0

I think the problem is your height: 100px in the outer div. If you remove this height attribute, do you get the result you're looking for?

Otherwise, I think batwad's probably knocked the nail on the head using three divs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.