Suppose you have some style and the markup:
ul { white-space: nowrap; overflow-x: visible; overflow-y: hidden; /* added width so it would work in the snippet */ width: 100px; } li { display: inline-block; }
When you view this. The <ul>
has a scroll bar at the bottom even though I've specified visible and hidden values for overflow x/y.
(observed on Chrome 11 and opera (?))
I'm guessing there must be some w3c spec or something telling this to happen but for the life of me I can't work out why.
UPDATE:- I found a way to achieve the same result by adding another element wrapped around the ul
. Check it out.
overflow-x hidden;
it removes the scroll but as i need the li elements to hide the border at the bottom so it gives that desired dashed effect. I don't uderstand why overflow-x: visible
creates a scroll bar. It shouldn't afaik.
overflow: hidden;
and a child inserted around the <ul>
being overflow: visible
.
After some serious searching it seems i've found the answer to my question:
from: http://www.brunildo.org/test/Overflowxy2.html
In Gecko, Safari, Opera, ‘visible’ becomes ‘auto’ also when combined with ‘hidden’ (in other words: ‘visible’ becomes ‘auto’ when combined with anything else different from ‘visible’). Gecko 1.8, Safari 3, Opera 9.5 are pretty consistent among them.
also the W3C spec says:
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’. The computed value of ‘overflow’ is equal to the computed value of ‘overflow-x’ if ‘overflow-y’ is the same; otherwise it is the pair of computed values of ‘overflow-x’ and ‘overflow-y’.
Short Version:
If you are using visible
for either overflow-x
or overflow-y
and something other than visible
for the other, the visible
value is interpreted as auto
.
another cheap hack, which seems to do the trick:
style="padding-bottom: 250px; margin-bottom: -250px;"
on the element where the vertical overflow is getting cutoff, with 250
representing as many pixels as you need for your dropdown, etc.
position: relative
or using wrappers was not possible, this was the only solution that worked, although it did also require adding a lot of ugly margins to child elements inside the element which I wanted to set overflow-x: hidden
on to compensate for the hacky padding. This saved me, though, so thanks!
I originally found a CSS way to bypass this when using the Cycle jQuery plugin. Cycle uses JavaScript to set my slide to overflow: hidden
, so when setting my pictures to width: 100%
the pictures would look vertically cut, and so I forced them to be visible with !important
and to avoid showing the slide animation out of the box I set overflow: hidden
to the container div of the slide. Hope it works for you.
UPDATE - New Solution:
Original problem -> http://jsfiddle.net/xMddf/1/ (Even if I use overflow-y: visible
it becomes "auto" and actually "scroll".)
#content {
height: 100px;
width: 200px;
overflow-x: hidden;
overflow-y: visible;
}
The new solution -> http://jsfiddle.net/xMddf/2/ (I found a workaround using a wrapper div to apply overflow-x
and overflow-y
to different DOM elements as James Khoury advised on the problem of combining visible
and hidden
to a single DOM element.)
#wrapper {
height: 100px;
overflow-y: visible;
}
#content {
width: 200px;
overflow-x: hidden;
}
overflow-x:visible;
and overflow-y:hidden
. Not the other way around.
overflow-x
and -y
: updated fiddle.
I've run into this issue when trying to build a fixed positioned sidebar with both vertically scrollable content and nested absolute positioned children to be displayed outside sidebar boundaries.
My approach consisted of separately apply:
an overflow: visible property to the sidebar element
an overflow-y: auto property to sidebar inner wrapper
Please check the example below or an online codepen.
html { min-height: 100%; } body { min-height: 100%; background: linear-gradient(to bottom, white, DarkGray 80%); margin: 0; padding: 0; } .sidebar { position: fixed; top: 0; right: 0; height: 100%; width: 200px; overflow: visible; /* Just apply overflow-x */ background-color: DarkOrange; } .sidebarWrapper { padding: 10px; overflow-y: auto; /* Just apply overflow-y */ height: 100%; width: 100%; } .element { position: absolute; top: 0; right: 100%; background-color: CornflowerBlue; padding: 10px; width: 200px; }
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
auto
instead of hidden
.
There is now a new way of addressing this issue - if you remove position: relative
from the container which needs to have the overflow-y visible, you can have overflow-y visible and overflow-x hidden, and vice versa (have overflow-x visible and overflow-y hidden, just make sure the container with the visible property is not relatively positioned).
See this post from CSS Tricks for more details - it worked for me: https://css-tricks.com/popping-hidden-overflow/
For my use case, adding overflow-x:visible; overflow-y:clip
onto the div that has the overflow seems to give me the desired effect of hiding overflow on the Y axis while not giving me a scrollbar on the X axis (i have a carousel slider that was loading images full-size before scaling them back down again, and these images were taking up 75% of the page height on load, hence wanting no overflow-y
).
No parent wrapper div was needed, just a fixed height
set on the overflowing element. I realise this solution may not work for everyone, but it could certainly help some.
overflow: clip
is not yet supported on Safari.
I used the content + wrapper approach... but I did something different than mentioned so far: I made sure that my wrapper's boundaries did NOT line up with the content's boundaries in the direction that I wanted to be visible.
Important NOTE: It was easy enough to get the content + wrapper, same-bounds approach to work on one browser or another depending on various CSS combinations of position
, overflow-*
, etc., but I never could use that approach to get them all correct (Edge, Chrome, Safari, etc.).
But when I had something like:
#hack_wrapper { position:absolute; width:100%; height:100%; overflow-x:hidden; } #content_wrapper { position:absolute; width:100%; height:15%; overflow:visible; }
... all browsers were happy.
I was facing the same issue, the following solution worked (styles are applied to the parent block)
overflow-y: visible;
overflow-x: clip;
A small "hack" that works very well if you only want the first row visible (but still need overflow):
set gap really high so you are sure the second row is pushed out of the screen - eg:
gap: 10000rem;
It is really hacky but works great for something like a desktop nav with menus that need to overflow...
gap
property only applies (and is only designed for) flexbox and grid layouts. If you aren't using display: grid
or display: flex
, it does not do anything.
Success story sharing
overflow-x:visible
duringoverflow-y:hidden
without a parent/child hack? Pretty bunk, IMO.overflow-y: visible
. Boo CSS!