692

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;
}
<div>
  <ul>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
  </ul>
</div>

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.

JSFiddle

UPDATE:
I found a way to achieve the same result by adding another element wrapped around the ul.

JSFiddle

6
  • What is your desired result? jsfiddle.net/Kyle_Sevenoaks/3xv6A/2 Commented Jun 21, 2011 at 7:51
  • @kyle it should look a little more like: jsfiddle.net/3xv6A/5 Unfortunately if i set 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. Commented Jun 21, 2011 at 23:23
  • @JamesKhoury can you elaborate a bit in your solution? I can't really make it work Commented Oct 9, 2014 at 14:10
  • 1
    @GeorgeKatsanos The workaround: jsfiddle.net/3xv6A/9 relies upon the parent being overflow: hidden; and a child inserted around the <ul> being overflow: visible. Commented Oct 10, 2014 at 1:25
  • @JamesKhoury Do you think it can work for embed.plnkr.co/2rbaISwvzuKhyPEFpBKD Commented Oct 10, 2014 at 8:04

11 Answers 11

968

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.

Sign up to request clarification or add additional context in comments.

13 Comments

@Erwin: They probably decided that having an element with content overflowing in both x and y directions and having one clipped and the other showing would look weirder than forcing content to either be clipped in both directions or not at all (not to mention the potential layout issues that come with visible vs any other value). See these proofs-of-concept for what it would look like had they allowed overflow-x: visible with overflow-y: hidden and with overflow-y: auto.
Given that the OP was trying to achieve something completely different than what is shown in my examples, and that everybody seems to be kvetching about the same problem as the OP, I suspect there is a different problem at hand that is somehow necessitating setting conflicting overflow values, though given the lack of a description I don't know what it might be. The code given in the question does not even sufficiently reproduce the problem, let alone begin to describe it.
BoltClock's message and clever JSFiddle demonstration of what it would look like if separate overflows is very important and shows potential reasons why it is a bad idea but there are many examples, such as floating sub-menus, where absolute or relative positioning without scroll-bars just needs separate overflow control (to avoid other complicated solutions). W3C could allow separate overflow control and just highlight the issues and problems it causes.
There is of course the quite simple solution to this problem which should work in most scenarios (but isn't ideal) of having two containing elements for the content, one inside the other and with one having overflow-x or overflow-y set to overflow or to contain and scroll and the other element set the opposite axis and set to the opposite containment.
It's quite unfair and ad hominem to label the complaints "mindless". The fact is that the API offers what appear to be two independent variables that are very poorly documented to, in certain specific cases, automatically change themselves based on the value of the other. An improvement to the API would make it impossible to even attempt to set x: auto, y:hidden (and similar).
|
227

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.

6 Comments

This makes the horizontal scrollbar appear that far down
This also blocks pointer events for 250px below the element. But I found a way around that, and this solution is what I'm using.
In my particular scenario, where removing 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 tried this horizontally it results in the vertically scrollable div being horizontally scrollable too.
this hides the scrollbar any way to work around it?
|
111

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;
}

9 Comments

How does this apply? It does not seem to work on overflow-x or overflow-y.
I added a better / clear example of what I was talking about, actually is quite the same solution as OP updated on his post
This solution does not apply. The question is overflow-x:visible; and overflow-y:hidden. Not the other way around.
@TomasJansson @Edward It does work, you just have to swap where you apply the overflow-x and -y: updated fiddle.
this fails as soon as the wrapper gains a width for some reason - jsfiddle.net/ad1941k9/16
|
45

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.

9 Comments

Be aware that overflow: clip is not yet supported on Safari.
@TimDown Support was added on 2nd Feb 2022, though I'm not sure if this is live yet. Please see the dev notes here -> developer.apple.com/safari/technology-preview/release-notes and here -> trac.webkit.org/changeset/288973/webkit
EDIT : just like @TimDown said it is NOT comptable with safari... I have the Monterey OS, Safari v15.4 and it's not supported.
@AndrewWest it might be live but considering that a lot of people I know CAN'T make the updates because of the storage the clip method is still considered "not supported" :/
It's late 2023 and support seems pretty good now: caniuse.com/mdn-css_types_overflow_clip. I reckon it's the best solution right now.
|
28

I was facing the same issue, the following solution worked (styles are applied to the parent block)

overflow-y: visible;
overflow-x: clip;

1 Comment

And if you want to use this with a text-overflow: ellipsis;, you have to add min-width: 0;, see this thread on Chromium
20

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;
}
<p>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?</p>
<div class="sidebar">
  <div class="sidebarWrapper">
    <div class="element">
      I'm a sidebar child element but I'm able to horizontally overflow its boundaries.
    </div>
    <p>This is a 200px width container with optional vertical scroll.</p>
    <p>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?</p>
  </div>
</div>

3 Comments

I'm pretty sure this is the same solution as others have presented except with auto instead of hidden.
Hi, I have a similar problem. Could you please have a look at my question here: stackoverflow.com/questions/76568278/…. Thanks.
Thanks I ran into this very issue with a scrollable list where each item scales up when hovered so I needed overflow-y to be visible while overflow-x scrolls. The main issue as described in the docs is those two settings don't mix since overflow-y will become auto. Setting the list to overflow: visible allows elements to break outside the container without being clipped (in both directions), and then setting overflow-x: auto on the new parent container makes it scroll in the x direction instead of being visible, perfect!
18

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/

2 Comments

but that would require some javascript to position the element correctly if it is absolute
At this point you might as well use position: fixed. Keeping any ancestors from being positioned isn't very realistic.
10

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;
}
<!-- #hack_wrapper div created solely for this purpose --> 
<div id="hack_wrapper">
    <div id="content_wrapper">         
          ... this is an example of some content with far too much horizontal content... like, way, way, way too much content.
    </div>
</div>

... all browsers were happy.

Comments

3

This is what worked for me:

On the container:

  .container {
      overflow-y: visible;
      overflow-x: clip;
  }

On the contained item:

  .item {
      width: 500px; /* any fixed value or it did not render in the browser */
  }

Comments

-1

i noticed that while the overflow-x: hidden really causes the second vert scrollbar to appear, overflow: hidden doesn't so it might help.

the second vertical scroll btw causes scrolling bouncy issues on the iphones which is big problem. vertical scrolling is basically disabled with this issue.

another solution seems to be overflow-x: clip as suggested by others. but it works itself.

Comments

-6

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...

1 Comment

The 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.