Making A Div Vertically Scrollable Using CSS
Making A Div Vertically Scrollable Using CSS
Sabya_Samadder
Read
Discuss
Courses
Practice
Making a div vertically scrollable is easy by using CSS overflow property. There are different values in
overflow property. For example: overflow:auto; and the axis hiding procedure like overflow-x:hidden;
and overflow-y:auto;. It will make vertical and horizontal scrollable bar and the auto will make only
vertically scrollable bar.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that
will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div
will be vertically scrollable.
Example 1:
html
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color:Green;
div.scroll {
margin:4px, 4px;
padding:4px;
background-color: green;
width: 500px;
height: 110px;
overflow-x: hidden;
overflow-y: auto;
text-align:justify;
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
coding style, and try to make you are close to them. In case you
</div>
</center>
</body>
</html>
Output:
Example 2: In this example use auto in place of overflow-x:hidden; and overflow-y:auto; to make div
vertically scrollable.
html
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color:Green;
div.gfg {
margin:5px;
padding:5px;
background-color: green;
width: 500px;
height: 110px;
overflow: auto;
text-align:justify;
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
coding style, and try to make you are close to them. In case you
</div>
</center>
</body>
</html>
Output: