![]() ![]() 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 |