Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow-y: scroll with overflow-x: visible [duplicate]

Tags:

html

css

overflow

Is it possible to have an item overflow horizontally out of a vertically scroll-able list?

I have a codepen example here:

http://codepen.io/baskuipers/pen/GqQYRJ

var $item = $('#1'),
  $button = $('.button');

$button.on("click", function() {
  $item.toggleClass('addMargin');
});
.sidenav {
  width: 300px;
  background-color: grey;
  position: fixed;
  padding: 20px;
}
.addMargin {
  margin-left: 60px;
}
.item {
  width: 100%;
  overflow-y: auto;
  height: 100vh;
  z-index: 5;
  position: relative;
}
.sub-item {
  transition: margin-left 1s cubic-bezier(0.36, -0.48, 0, 2.22);
  background-color: orange;
  height: 100px;
  width: 100%;
  margin-bottom: 10px;
  z-index: 10;
  position: relative;
}
body {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sidenav">
  <button class="button">test</button>
  <div class="item">
    <div id="1" class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
  </div>
</div>

In the example I'd like to have the yellow item stick out of the list. It is not a problem about the visibility of the scrollbars.

Any suggestions? CSS / JavaScript?

Thanks!

like image 377
Bas Kuipers Avatar asked Jul 19 '16 14:07

Bas Kuipers


People also ask

What is overflow-y and overflow-X?

overflow-x specifies what to do with the left/right edges of the content. overflow-y specifies what to do with the top/bottom edges of the content. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.

What is the use of overflow-X?

Definition and Usage The overflow-x property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the left and right edges.

What is the difference between overflow auto and scroll?

The difference For that, you need overflow: auto , which lets a browser automatically determine if a scroll bar is needed — or not. So in short: overflow: scroll : Always show a scroll bar. overflow: auto : Show a scroll bar when needed.


1 Answers

After reading https://stackoverflow.com/a/6433475/4386196 it seems like the answer is no, it's not possible. You would need to set overflow-x: visible, but since you've set overflow-y then it is treated as auto which hides the content.

This probably doesn't solve your problem exactly, but if you add:

margin-right: -100px; padding-right: 100px;

to .item you can move the scrollbar and give more room for overflow within the box. Closest I could come to a solution.

like image 80
Zachary Wand Avatar answered Sep 22 '22 00:09

Zachary Wand