Overflow in oven animated3/11/2024 panel selector can clip this element */įrom John Pearse, sent to me after the comments had closed: Or, even better, perhaps we could specify the clipping parent by a CSS selector: /* Fair warning: not real code */ * only an ancestor 2 levels up can clip this element */ It’d be nice if we could specify a clip depth, which would control which ancestor in the hiearchy would be responsible for clipping a particular element. Unfortunately, this method of showing items that would otherwise be hidden is very obscure. Now we can have as many levels of nested submenus as we want, and we won’t get any undesired clipping. See the Pen Scrollable menu with pop out submenus by Agop ( on CodePen.Īnd that’s it! Since neither the menus nor the menu items are positioned, the submenus are able to pop out of the hidden/scrollable overflow. Then, whenever the user hovers over a menu item, we can position the submenu wrappers using a bit of JavaScript: Knowing this, we can add a wrapper around the menus to act as the closest positioned ancestor for each submenu. See the Pen Scrollable menu with pop out submenus (step 1) by Agop ( on CodePen.īasically, in order for an absolutely positioned element to appear outside of an element with overflow: hidden, its closest positioned ancestor must also be an ancestor of the element with overflow: hidden. In this case, they don’t have a positioned ancestor, so they’re positioned relative to : Interestingly enough, if we omit the position: relative from the menu items, the submenus do show up, positioned based on their closest positioned ancestor. So we can’t have visible horizontal overflow if the vertical overflow is invisible, and vice versa.Īnd if we can’t have visible horizontal overflow, we can’t have our pop out submenus! The Solution The computed values of ‘overflow-x’ and ‘overflow-y’ are the same as their specified values, except that some combinations with ‘visible’ are not possible: if one is specified as ‘visible’ and the other is ‘scroll’ or ‘auto’, then ‘visible’ is set to ‘auto’. If we look at the W3C spec, we find the following explanation: What gives? Why do we still get scrollbars? The Problem See the Pen Scrollable menu with pop out submenus (broken #2) by Agop ( on CodePen. Oh, of course, we used overflow: auto – perhaps if we use overflow-x: visible, the horizontal overflow of the submenus will be visible: See the Pen Scrollable menu with pop out submenus (broken) by Agop ( on CodePen. So you’re tasked with creating a scrollable menu with submenus that pop out when you hover over a parent menu item.Ĭreate a list for the menu, add some nested lists for the submenus, position the nested lists based on their parent list items, voilà! You’d think that’s what overflow-x and overflow-y are for, but it’s not that simple. Agop ran into an interesting scenario where he needed an element to be scrollable in one direction, while allowing the overflow in the other direction. The following is a guest post by Agop Shirinian.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |