
long links or words would cause the floats to expand widthways and perhaps break the layout if it weren't there. Overflow: hidden on the same elements could also be to stop the expanding box problem, which is also IE6 and below. It should perhaps be in a conditional (separate IE file) to highlight that it's a workaround though. As everyone else ignores it it causes no other problems that I'm aware of. One being the Double Margin bug, the other similar Duplicate Indent bug, because of this some coders add display:inline to all their floats to avoid any IE errors. It's true, elements that are floated are supposed to ignore the display property so it should be unnecessary BUT the reason it could be there is that it is a cure for 2 x IE6 bugs. You can't float:left and display:inline at the same time, So can someone explain what display:inline and overflow:hidden actually do?Īnd how/why does the middle column magically get defaulted between the two outer columns that are floated to left and right respectively? A true game-changer for creating a more positive user experience (UX) in my Angular, Single-Page Applications (SPA).I'm analyzing this CSS file to better learn tableless design using the float method (forgot the name of this style, I know the other one is called absolute positioning).īasically there is a outer div tag that defines the width of page, and then a 3 column layout that has 1 div tag that is floated to the left, then another to the right while the main contain section is just left alone and somehow gets centered between the two floats (not sure how that works). The overscroll-behavior CSS property is perfect for things like rich HTML dropdown menus, modal windows, and fly-out panels. This is awesome! I will literally be shipping this to production today. However, with the scrollable container on the right, which uses overscroll-behavior: contain, the scrolling is contained within the element - no "scroll chaining" occurs and the mouse wheel never affects the body scroll.
#Overflow hidden meaning code#
Now, if we run this HTML and CSS code in the Chrome browser, we get the following output:Īs you can see, when users scrolls to a local maxima within the scrollable container on the left, subsequent use of the scroll wheel causes the body element to scroll. Notice that the only difference is that the overflow: auto container on the right has the overscroll-behavior directive. Overscroll-behavior: contain /* Prevent SCROLL-CHAINING to parent elements. Overflow: auto /* The panel becomes SCROLLABLE due to content overflow.

Using CSS Overscroll-Behavior To Prevent Scrolling Of Parent Containers From Within Overflow Containers The box is made up of four layers: the content itself, padding, a border, and a margin). The container on the left has no modifying CSS properties while the container on the right has the CSS property overscroll-behavior: contain: Overflow in CSS refers to content that is too large for an elements box ( HTML always creates a rectangular box. To see this in action, I have two overflow: auto elements laid-over a scrollable body element. This will prevent the "scroll chaining" behavior, which will, in turn, keep the mouse-wheel active within the target element. To do this (in Chrome, Firefox, and Edge), we can add the CSS property overscroll-behavior: contain to the overflow: auto element. Explanation of your CSS: margin: 0 auto horizontally aligns the element at the center overflow:hidden prevents scrollbars from appearing width:980px sets the width of the element to be 980px. Really, what we want to happen is to have the scrolling behavior always contained within the overflow: auto element. 6 Answers Sorted by: 11 overflow:hidden prevents scrollbars from showing up, even when they're necessary.

More often than not, this leads to an unexpected and undesired user experience (UX). Once this "scroll chaining" occurs, subsequent use of the mouse-wheel may not be applied to the overflow: auto element instead, the expression of the scrolling may continue to manifest in the ancestor element.

However, when the user hits the top or the bottom of that content, the browser may start to scroll one of the ancestor elements, most commonly the body element. If you have an overflow: auto element, the user can scroll the content contained within that element. View this code in my JavaScript Demos project on GitHub. Run this demo in my JavaScript Demos project on GitHub.
