Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow specific tag to override overflow:hidden

Tags:

html

css

I've got a <div>, that's a certain height and width, and overflow:hidden so that specfic inner images are clipped; however I want one image in the <div> to pop out of the border (ie to override the overflow:hidden), how do I do this?

like image 642
user965369 Avatar asked Jan 12 '12 14:01

user965369


People also ask

How do I break out of overflow hidden?

We have a dropdown-menu that gets filled with suggestions when the user type (type 'c' in the search field to see). This dropdown-menu is currently hidden behind the menubar, because it has "overflow hidden". We can break out, if we remove the top:100% and set position to fixed .

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.

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.


2 Answers

The trick is to keep the overflow:hidden element with position:static and position the overflowing element relative to a higher parent (rather than the overflow:hidden parent). Like so:

.relative-wrap {      /*relative on second parent*/      position: relative;  }    .overflow-wrap {      height: 250px;      width: 250px;      overflow: hidden;      background: lightblue;            /*no relative on immediate parent*/  }    .respect-overflow {      position: relative;      top: 75px;      left: 225px;      height: 50px;      width: 50px;      background: green;      }  .no-overflow {      position: absolute;      top: 150px;      left: 225px;      height: 50px;      width: 50px;      background: red;  }
<div class="relative-wrap">            <div class="overflow-wrap">                    <div class="respect-overflow">                    </div>          <div class="no-overflow">                        </div>                </div>        </div>

I also want to note, a very common use case for the desire to have an element overflow its container in this way is when you want animate the height of a dropdown or container from X to 0, and therefore need to have overflow: hidden on the container. Usually you have something inside the container that you want to overflow regardless. Since these elements are only accessibly when the container is "open", you can take advantage and set the overflow back to visible after the container is fully open, and then set it back to hidden before trying to animate the container back to height: 0.

like image 176
parliament Avatar answered Nov 11 '22 18:11

parliament


I know this is an old post, but this can be done (at least in Chrome). I figured this out about two years ago and it's saved me a couple times.

Set the child to have position of fixed and use margins instead of top and left to position it.

#wrapper {     width: 5px;     height: 5px;     border: 1px solid #000;     overflow: hidden; }  #parent {     position: relative; }  button {     position: fixed;     margin: 10px 0px 0px 30px; } 

Here is an example: http://jsfiddle.net/senica/Cupmb/

like image 27
Senica Gonzalez Avatar answered Nov 11 '22 18:11

Senica Gonzalez