views:

931

answers:

3

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 CSS 2 to show only vertical but not horizontal scrollbars. Is there anything I can do with javascript to hide the horizontal scrollbar?

+4  A: 

You can use css like this:

overflow-y: scroll;
overflow-x: hidden;
Nick Craver
I'm seeing that as CSS3, and it doesn't work in Firefox when I test it. I also see that this is available as an IE-only property from way back in the day.
WIlliam Jones
@wiliamjones - This works in firefox...do you have an example page? Might be some other layout reason it's not working.
Nick Craver
@william - Here's a complete example of it working, test in firefox :) http://jsfiddle.net/qpZ8k/
Nick Craver
You're right, it does work with Firefox, it's the Prototype javascript library that isn't compatible with this attribute, which was easy enough to work around.Is this property generally reliable across browsers?
WIlliam Jones
@williamjones - Yup, it's usually the case with these things, browsers implement it, then it's a standard later as an afterthought.
Nick Craver
+1  A: 

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

overflow-x: hidden;
overflow-y: scroll;
Kevin
+1  A: 

Using wrap=virtual in your HTML form boxes gets rid of the horizontal scrollbar at the bottom of the box:

  <textarea name= "enquiry" rows="4" cols="30" wrap="virtual"></textarea>

See example here : http://jsbin.com/opube3/2 (Tested on FF and IE)

metal-gear-solid