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

CSS to show only horizontal and vertical scroll bar in div

  Author : Shailendra Chauhan
Updated On : 14 Jul 2012
Total Views : 37,390   
 

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.

YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
11 DEC
ASP.NET MVC with AngularJS Development (offline)

Sat-Sun 09:30 AM-11:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (11:00 AM-12:30 PM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+