Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid an Element from being cut off when they are inside a "overflow: hidden" element

Tags:

html

css

I'm using the equal heights CSS trick as outlined on this page.

It was all working fine until today when I need to add a dialogue box inside one of the columns, which is absolutely positioned to take it out of the flow. The problem is that since the container has "overflow: hidden" on it, the dialogue is being cut off when it overflows.

Aside from bringing the dialogue outside of the container element, is there any possible way to get it to show via CSS?

Here's a small example demonstrating what I've mentioned.

<style>
.container { overflow: hidden; margin-top: 30px }
.col { 
    float: left;
    padding-bottom: 2000px;
    margin-bottom: -2000px;
    border-right: 1px solid black;
    width: 100px;
    background-color: grey;
}
.col.third { border-right: none }

#div-a { position: relative }
#div-b {
    position: absolute;
    background-color: red;
    width: 35px;
    height: 350px;
    bottom: 0;
    right: 0;
    margin: 5px;
    border: 2px solid black;
}
</style>

<div class="container">
    <div class="col first">
        <p style="height: 100px">One</p>
    </div>
    <div class="col second">
        <p style="height: 300px">Two</p>
        <div id="div-a">
            <!-- this gets cut off by the "overflow: hidden" on div.container -->
            <div id="div-b">
                Foo
            </div>
        </div>
    </div>
    <div class="col third">
        <p style="height: 200px">Three</p>
    </div>
</div>

You see that div#div-b is cut off at the top when it overflows in the div.container element.

like image 280
jay_soo Avatar asked Mar 05 '09 18:03

jay_soo


People also ask

How do I bypass overflow hidden in CSS?

Use overflow: hidden instead. Use overflow-x : scroll and overflow-y : hidden , or overflow: scroll hidden instead. Use overflow-x : hidden and overflow-y : scroll , or overflow: hidden scroll instead. Use overflow: clip instead.

What happens if we use overflow hidden?

hidden - The overflow is clipped, and the rest of the content will be invisible. scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content. auto - Similar to scroll , but it adds scrollbars only when necessary.

What causes an element to overflow?

Overflow happens when there is too much content to fit in a box. CSS provides various tools to manage overflow. As you go further with CSS layout and writing CSS, you will encounter more overflow situations.

Which property allows the content to overflow the borders of its containing element?

CSS provides a property called overflow that tells the browser what to do if the box's contents are larger than the box itself. Allows the content to overflow the borders of its containing element. The content of the nested element is simply cut off at the border of the containing element and no scrollbars are visible.


2 Answers

Unfortunately what you want to do is impossible without bringing the dialogue outside of the container element.

Your best bet is to make the dialog element a sibling of the container and position it that way.

like image 111
Allie the Icon Avatar answered Sep 28 '22 09:09

Allie the Icon


Unfortunately no... I don't think there's a way to circumvent overflow: hidden with absolute position. You may experiment with position: fixed, but you won't be positioning under quite the same conditions if you use it.

like image 38
Joshua Shannon Avatar answered Sep 28 '22 08:09

Joshua Shannon