21
NovCSS to show only horizontal and vertical scroll bar in div
Sometimes we need to add scroll bar to a div or span whenever text in the div or span get overflow. scroll bar is supported in all browsers like IE 5+, FF 3.5+, and Safari, Opera etc. To show scroll bar, we need to specify overflow property of css to "visible" or "auto".
Horizontal and vertical scroll bar
.scrollbar { overflow: auto; /*for horizontal and vertical scroll bars */ } /* or you can set scrolling in x and y direction */ .scrollbarxy { overflow-x: auto; /*for horizontal scroll bar */ overflow-y: auto; /*for vertical scroll bar */ }
Only, Horizontal scroll bar
/* Show only horizontal scrollbar */ .hscrollbar { overflow-x: auto; /*for horizontal scroll bar */ overflow-y: hidden; /*for hiding vertical scroll bar */ }
Only, Vertical scroll bar
/* Show only vertical scrollbar */ .vscrollbar { overflow-x: hidden; /*for hiding horizontal scroll bar*/ overflow-y: auto; /*for vertical scroll bar*/ }
Note
To show scroll bar always set overflow to "visible". It will show scroll bar whether text get overflow or not.
To show scroll bar only, when text get overflowed, set overflow property to "auto".
Summary
In this article I try to explain, how you can scroll overflow text in div or span using css. I hope after reading this article you will be able to use this trick in your code. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.