CSS
In this tutorial we will learn about CSS overflow.
We use the overflow
property when we want to add scroll bar or clip the content inside an element.
Overflow works only for block element having height specified.
Following are the values that we can use.
In the following example we have set the overflow property of the div (having id mycontainer) to visible. We have set the width and height of the element and written a longer text and hence the extra content will get displayed outside the element.
div#mycontainer {
overflow : visible;
height : 100px;
width : 300px;
padding : 15px;
background-color : #eee;
}
Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
In the following example we have set the overflow property of the div (having id mycontainer) to auto. We have set the width and height of the element and written a longer text and hence scroll bar will be added (if needed) to the element.
div#mycontainer {
overflow : auto;
height : 100px;
width : 300px;
padding : 15px;
background-color : #eee;
}
Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
In the following example we have set the overflow property of the div (having id mycontainer) to hidden. We have set the width and height of the element and written a longer text and because of the hidden value the extra content will not be displayed and no scroll bar will be added.
div#mycontainer {
overflow : hidden;
height : 100px;
width : 300px;
padding : 15px;
background-color : #eee;
}
In the following example we have set the overflow property of the div (having id mycontainer) to scroll. We have set the width and height of the element and written a longer text and because of the scroll value scroll bar will be added both horizontally and vertically.
div#mycontainer {
overflow : scroll;
height : 100px;
width : 300px;
padding : 15px;
background-color : #eee;
}
Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
We use the overflow-x
property for horizontal scroll bar.
We use the overflow-y
property for vertical scroll bar.
In the following example we have set the overflow-x and overflow-y property of the div (having id mycontainer).
div#mycontainer {
overflow-x : auto;
overflow-y : scroll;
height : 100px;
width : 300px;
padding : 15px;
background-color : #eee;
}
Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
ADVERTISEMENT