Please enable Javascript to correctly display the contents on Dot Net Tricks!

CSS to show only horizontal and vertical scroll bar in div

 Print 
  Author : Shailendra Chauhan
Posted On : 19 Jun 2012
Total Views : 43,955   
Updated On : 14 Jul 2012
 

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

  1. To show scroll bar always set overflow to "visible". It will show scroll bar whether text get overflow or not.

  2. 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.



Free Interview Books
 
COMMENTS
18 NOV
Angular with Firebase (Classroom)
04:00 PM-07:00 PM IST(+5:30)
18 NOV
Angular2+4 with Firebase (Online)
10:30 AM-12:30 PM IST(+5.30 GMT)
11 NOV
ASP.NET MVC (Online)
08:00 AM-10:00 AM IST / 09:30 PM To 11:30 PM(CST)
11 NOV
ASP.NET MVC (Classroom)
09:00 AM to 12:00 AM
7 NOV
Developing Microsoft Azure Solutions (Online)
07:00 AM-08:30 AM IST/ 8:30 Pm -10:00 PM CST
14 OCT
Angular2 and Angular4 (Online)
03:00 PM-05:00 PM IST (+5.30GMT)
12 OCT
ASP.NET Core (Online)
09:00 PM - 11:00 PM IST(+5:30 GMT)
10 OCT
Microsoft Azure Infrastructure Solutions (Online)
08:00 AM-09:30 AM IST / 09:30 PM -11:00 PM CST
LIKE US ON FACEBOOK
 
+