Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception to the overflow:hidden; property

Tags:

How is it possible to make an exception on the overflow:hidden; container property to a matched set of child elements?

Here's a sample scene:

<div style = "overflow:hidden;">    <p>item</p>    <p>item</p>    <p class="special">item that needs to show itself outside the parent borders</p> </div> 

I do have a reason why I'm doing this :] I'm building a pretty complex scrolling menu whose elements are expanding out of the menu's borders. The menu obviously clips everything outside its borders since it's scrolling around.

Here's a chunk of code relevant to the issue: http://jsfiddle.net/Birowsky/fNLbP/15/

Uncomment the marked line in the JavaScript to see the issue below the 'special item'. You might notice that the scrolling isn't working, it's ok, I think it's fiddle issue.

like image 550
Daniel Birowsky Popeski Avatar asked Mar 31 '11 12:03

Daniel Birowsky Popeski


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 .

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 does the overflow hidden property specify?

overflow: hidden 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.


2 Answers

You can make the special element to be absolutely positioned

.special{  position:absolute; } 

But this will only work when the .special does not define a position (top/left/bottom/right), and also it will not be used if you later want to calculate the height of the parent div..

example : http://jsfiddle.net/gaby/aT3We/

The requirement though is a bit weird, and it might be better to rethink the whole issue..
(what exactly are you trying to achieve with this ?)

like image 103
Gabriele Petrioli Avatar answered Oct 19 '22 06:10

Gabriele Petrioli


I don't think you'll be able to find a way to do this. Even if you do, I'd recommend against using it because it probably won't be future-proof or very cross-browser compatible.

In the case of a menu, you're probably better off putting these items in separate divs. I'd need to see your code in context to recommend a specific way of doing things, but layering your elements kinda like this might work for you:

<div style = "overflow: hidden; width: 200px; height: 100px; margin: 0; padding: 0; background-color: #CCCCCC; z-index: 1;">    <p>item</p>    <p>item</p> </div> <div style = "overflow: visible; width: 200px; height: 100px; margin: -30px 0 0 0; padding: 0; z-index: 2;">    <p class="special">item that needs to show itself outside the parent borders</p> </div> 

If that doesn't fit your needs, maybe you could describe the structure of your menus better so that we can understand what you need? Do you have a link to an example, perhaps?

Edit based on new information

After looking at your example link, it looks like what you want to do is clip content horizontally, while still allowing it to overflow vertically. You can do this by using a very high height value, and then setting a negative bottom margin:

<div style="width: 200px; height: 2000px; margin: 0 0 -1960px 0; overflow: hidden;">     <p>Thisisaverylongsentencedesignedtooverflowthewindowverticallysopleasepermitmetotypeitwithoutandspaces</p>     Item 1<br />     Item 2<br />     Item 3<br />     Item 4<br /> </div> 

Is this what you want?

like image 21
Joshua Carmody Avatar answered Oct 19 '22 06:10

Joshua Carmody