How do I remove the horizontal scrollbar in a div?
Asked Answered
C

17

169

When I set overflow: scroll, I get horizontal and vertical scrollbars.

Is there a way to remove the horizontal scrollbar in a div?

Carrera answered 10/12, 2010 at 5:28 Comment(0)
F
260
overflow-x: hidden;

Fortitude answered 10/12, 2010 at 5:30 Comment(1)
it's a bad solution. Because in this case you just hide horizontal scroll in container. But if this container is too wide your content will not be fit in your container.Hillier
M
66

Don't forget to write overflow-x: hidden;

The code should be:

overflow-y: scroll;
overflow-x: hidden;
Major answered 4/11, 2012 at 13:4 Comment(0)
B
27

CSS

overflow-y: scroll;

See it on jsFiddle.

Notice if you remove the -y from the overflow-y property, the horizontal scroll bar is shown.

Benner answered 10/12, 2010 at 5:32 Comment(0)
N
23

With overflow-y: scroll, the vertical scrollbar will always be there even if it is not needed. If you want y-scrollbar to be visible only when it is needed, I found this works:

.mydivclass {overflow-x: hidden; overflow-y: auto;}
Nosography answered 31/12, 2013 at 7:50 Comment(0)
C
22

To hide the horizontal scrollbar, we can just select the scrollbar of the required div and set it to display: none;

One thing to note is that this will only work for WebKit-based browsers (like Chrome) as there is no such option available for Mozilla.

In order to select the scrollbar, use ::-webkit-scrollbar

So the final code will be like this:

div::-webkit-scrollbar {
  display: none;
}
Crappie answered 21/8, 2018 at 18:35 Comment(0)
M
21

Add this code to your CSS. It will disable the horizontal scrollbar.

html, body {
    max-width: 100%;
    overflow-x: hidden;
}
Mazurek answered 26/10, 2015 at 7:28 Comment(0)
E
20

Removes the HORIZONTAL scrollbar while ALLOWING for scroll and NOTHING more.

&::-webkit-scrollbar:horizontal {
  height: 0;
  width: 0;
  display: none;
}

&::-webkit-scrollbar-thumb:horizontal {
  display: none;
}
Elsey answered 18/12, 2020 at 16:30 Comment(1)
Thanks for apparently being the only person on the internet accurately answering this lol! Nice oneShien
T
19

No scroll (without specifying x or y):

.your-class {
   overflow: hidden;
}

Remove horizontal scroll:

.your-class {
   overflow-x: hidden;
}

Remove vertical scroll:

.your-class {
   overflow-y: hidden;
}
Tympanum answered 9/10, 2014 at 19:35 Comment(1)
OP needs scrolling without scrollbarUs
L
9

To remove the horizontal scroll bar, use the following code. It 100% works.

html, body {
    overflow-x: hidden;
}
Longanimity answered 20/1, 2019 at 14:43 Comment(0)
E
6

If you don't have anything overflowing horizontally, you can also just use

overflow: auto;

and it will only show scrollbars when needed.

See The CSS Overflow Property

Eastwood answered 18/11, 2014 at 19:36 Comment(0)
W
6
overflow-x:hidden;

However, it may happen that your content on the website may not show. So best to inspect element and check the widths of your divs or sections, and remove any right/left margins it may have put in extra. Much better solution

Whelm answered 30/3, 2021 at 11:45 Comment(0)
L
2

Use:

overflow: auto;

This will show the vertical scrollbar and only if there is a vertical overflow, otherwise, it will be hidden.

If you have both an x and y overflow, then both x and y scrollbars will be shown.

To hide the x (horizontal) scrollbar, even if present simply add:

overflow-x: hidden;

body {
    font-family: sans-serif;
}

.nowrap {
    white-space: nowrap;
}

.container {
    height: 200px;
    width: 300px;
    padding 10px;
    border: 1px solid #444;

    overflow: auto;
    overflow-x: hidden;
}
<div class="container">
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
  <li>Item 4</li>
  <li>Item 5</li>
  <li>Item 6</li>
  <li>Item 7</li>
  <li class="nowrap">Item 8 and some really long text to make it overflow horizontally.</li>
  <li>Item 9</li>
  <li>Item 10</li>
  <li>Item 11</li>
  <li>Item 12</li>
  <li>Item 13</li>
  <li>Item 14</li>
  <li>Item 15</li>
  <li>Item 16</li>
  <li>Item 17</li>
</ul>
</div>
Lavoie answered 22/2, 2018 at 21:55 Comment(0)
S
2

To hide the scrollbar, but keep the behaviour.

div::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}

There are limitations to this.

Supercharger answered 18/12, 2019 at 2:56 Comment(0)
A
1

Use This chunk of code..

.card::-webkit-scrollbar {
  display: none;
}
Abed answered 8/2, 2020 at 14:23 Comment(1)
This does remove both scrollbars (y and x). Still a good indication thoughInconsistent
H
0

Hide Scrollbars

step 1:

go to any browser for example Google Chrome
click on keyboard ctrl+Shift+i inspect use open tools Developer

step 2:

Focused mouse on the div and change style div use try this:
 overflow: hidden; /* Hide scrollbars */

now go to add file .css in project and include file

Hamil answered 6/2, 2021 at 18:42 Comment(0)
K
0

lastly i encountered this issue the overflow-x property did not help me and i think its a banal solution, i recommend to inspect and check the elements that are potentially big and take more size than the other elements in your page, don't forget to check the width of some of your container the width based on view (vw) property can restrict your containers and its so practical. good luck.

Kyla answered 7/2, 2023 at 9:30 Comment(0)
S
-2

I had been having issues where I was using

overflow: none;

But I knew CSS didn't really like it and it didn’t work 100% for how I wanted it to.

However, this is a perfect solution as none of my content is supposed to be larger than intended and this has fixed the issue I had.

overflow: auto;
Scrutineer answered 13/8, 2015 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.