![]() 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. What is overflow in CSS?īefore we look at what the overflow property in CSS means, we first need to understand that “ everything in CSS is a box.” We resize these boxes to fit our desired design by decreasing or increasing the height and width.The following is a guest post by Agop Shirinian. I think we will have lots of fun while learning it. This article will discuss what an overflow scroll in CSS is, explain what causes this issue, and suggest ways to fix the problem, including: This is the scrolling overflow problem related to our CSS styling. Nevertheless, every frontend developer has encountered this problem more often than not. Have you ever seen a horizontal scroll bar on your screen because your web content did not fit? Have you opened a modal and the rest of the page (the background content) is still scrolling? Have you tested your site with a different browser, yet the page scrolls horizontally? I'm also skilled with React for web, React Native for Android apps, and Tailwind CSS. I am highly skilled in HTML, CSS, and JS to build web-accessible and progressive apps. Chimezie Innocent Follow I am Chimezie, a software developer based in Nigeria.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |