650

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. Check it out.

6
  • What is your desired result? jsfiddle.net/Kyle_Sevenoaks/3xv6A/2
    – Kyle
    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. Jun 21, 2011 at 23:23
  • @JamesKhoury can you elaborate a bit in your solution? I can't really make it work 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. Oct 10, 2014 at 1:25
  • @JamesKhoury Do you think it can work for embed.plnkr.co/2rbaISwvzuKhyPEFpBKD Oct 10, 2014 at 8:04

10 Answers 10

924

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.

24
  • 391
    I understand that the W3C specifies it this way, but what is the motivation behind it? I find it quite weird and inconsistent behavior, resulting in messy work-arounds which require adding trivial HTML-elements.
    – Erwin
    Nov 26, 2012 at 16:04
  • 37
    @Erwin I agree, Hopefully someone decides to update the spec. Nov 26, 2012 at 23:02
  • 181
    You're right but it makes no sense. The most common reason you'd even want x and y is so you can make one hidden and the other visible. Apr 3, 2014 at 20:12
  • 134
    This is crippling. Why can't we allow overflow-x:visible during overflow-y:hidden without a parent/child hack? Pretty bunk, IMO.
    – Slink
    Jun 27, 2014 at 14:14
  • 60
    This is totally crippling. I was trying to make a bunch of dropdown links in a Bootstrap navbar scroll horizontally, but that breaks the dropdowns, which rely on overflow-y: visible. Boo CSS!
    – Andy
    Jul 8, 2015 at 18:57
207

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.

7
  • 32
    This makes the horizontal scrollbar appear that far down
    – nafg
    Dec 10, 2017 at 23:16
  • 3
    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. Apr 27, 2018 at 20:13
  • 2
    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! Dec 21, 2018 at 11:33
  • I tried this horizontally it results in the vertically scrollable div being horizontally scrollable too. Oct 17, 2019 at 21:34
  • 1
    this hides the scrollbar any way to work around it? Jan 16 at 5:18
108

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;
}
11
  • 17
    How does this apply? It does not seem to work on overflow-x or overflow-y. Jul 3, 2013 at 4:30
  • 1
    @Macumbaomuetre That is clearer, thank you +1. It is similar to the "update" I added. Originally I wasn't able to alter the wrapping div and my solution ended up similar to: jsfiddle.net/3xv6A/338 Jul 5, 2013 at 0:59
  • 13
    This solution does not apply. The question is overflow-x:visible; and overflow-y:hidden. Not the other way around.
    – Jakobovski
    Nov 12, 2015 at 13:07
  • 3
    @TomasJansson @Edward It does work, you just have to swap where you apply the overflow-x and -y: updated fiddle. Jun 30, 2016 at 12:57
  • 4
    this fails as soon as the wrapper gains a width for some reason - jsfiddle.net/ad1941k9/16 Dec 18, 2017 at 6:26
32

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.

10
19

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
  • 4
    I'm pretty sure this is the same solution as others have presented except with auto instead of hidden. Feb 15, 2017 at 0:43
  • Hi, I have a similar problem. Could you please have a look at my question here: stackoverflow.com/questions/76568278/…. Thanks.
    – TCL
    Jun 27 at 20:33
  • 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!
    – Stephen
    Nov 30 at 18:50
19

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
  • 8
    but that would require some javascript to position the element correctly if it is absolute
    – gaurav5430
    Dec 23, 2019 at 11:14
  • 1
    At this point you might as well use position: fixed. Keeping any ancestors from being positioned isn't very realistic.
    – sallf
    Sep 9, 2022 at 21:52
12

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

overflow-y: visible;
overflow-x: clip;
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.

2

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 */
  }
1
  • 2
    Thank you so much, I've never heard of clip, that is super helpful when you need to hide one axis and make the other visible. Cheers, man!
    – RVFET
    Sep 22 at 9:43
-5

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
  • 1
    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.
    – TylerH
    Nov 24, 2021 at 14:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.