2

I want horizontal overflow and when the screen width is not that wide the DIV starts scrolling right - left, but I want it to look not that ugly I have it right now (scrollbars in the bottom of the div).

.wrapper {
    position: relative;
    overflow-x: scroll;
    overflow-y: hidden;
}

.content {
    margin: 0 auto;
    width: 1198px;
}

HTML

<div class=wrapper>
  <div class=content">
    My content here.. 
  </div>
</div>

And the other question - is there setting for CSS what allows "swipe" for the div instead of "drag and move".. ?

7
  • set overflow-x:auto to enable scrolling only when there is content overflow Commented Aug 25, 2016 at 12:14
  • 1
    don't set width in px set the width in percentage width:100%; it helps your div fit to screen Commented Aug 25, 2016 at 12:15
  • 1
    @Chris not really what I need, I don't care if it scollable when not that wide.. I just don't like those scroll bar when scroll is in action. Commented Aug 25, 2016 at 12:15
  • then you gotta use custom scrollbar, there are many libraries for this you can google for Commented Aug 25, 2016 at 12:16
  • Oh you want to be able to scroll but don't show the scrollbar. Commented Aug 25, 2016 at 12:18

1 Answer 1

4

For a pure CSS solution with browser support you could use the combination of ::-webkit-scrollbar and some padding like this:

.wrapper {
    width: 100%;
    height: 400px;
    position: relative;
    overflow: hidden;
}

.content {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding-right: 17px; /* This hides the right scrollbar */
    padding-bottom: 17px; /* This hides the bottom scrollbar */
}

.content::-webkit-scrollbar { 
    display: none; 
}
<div class="wrapper">
  <div class="content">
    <img src="https://via.placeholder.com/1500x700" />
  </div>
</div>

Better to play around with in JSFiddle: https://jsfiddle.net/thepio/pavb2hfy/

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

3 Comments

Amazing! I think I was looking for this.. What about cross-browser support? I just checked on Chrome, Safari and FF (all OS X), but others .. ?
Well, you know I just tested with those exact browsers and OS myself also. I don't have the equipment to test on other browsers/OS right now but if you do test them please let me also know of the results. I would imagine this working on most of them. If you want to make sure it's cross-browser I would suggest some plugin.
YOU'RE THE MAN!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.