Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide html horizontal but not vertical scrollbar

I have an HTML textarea that is of fixed width, but variable height. I would like to set overflow:scroll and be able to show a vertical scrollbar, but not a horizontal one. I am not able to use overflow:auto due to other things specific to my situation.

I know there is no way using CSS2 to show only vertical but not horizontal scrollbars. Is there anything I can do with JavaScript to hide the horizontal scrollbar?

like image 281
William Jones Avatar asked Apr 07 '10 17:04

William Jones


People also ask

How do I hide horizontal scrollbar but still scroll?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.

How can I hide scrollbar in iframe but still scroll?

1. Set the overflow of the parent div as hidden. 2. Set the overflow of the child div to auto and the width 200% (or anything more than 100%, or more than the width of the parent - so that the scrollbar gets hidden).

Why does horizontal scrollbar appear in HTML?

Web browsers do not take into account the width of the scrollbar on the side of a page when computing width values, so since we have a page that is longer than a single viewport, part of our page is being rendered behind the vertical scroll bar, causing the browser to display a horizontal scroll bar.


2 Answers

You can use css like this:

overflow-y: scroll; overflow-x: hidden; 
like image 171
Nick Craver Avatar answered Sep 18 '22 15:09

Nick Craver


Use CSS. It's easier and faster than javascript.

overflow-x: hidden; overflow-y: scroll; 
like image 42
Kevin Avatar answered Sep 18 '22 15:09

Kevin