Reputation: 1526
I want to make a <div>
with a really long height (2000px, more or less) and I want to only show some of it (400px-500px), and have a scrollbar to browse through it.
I have no idea where to start, does anyone has some articles/how-tos or give me directions on how to do this? Thanks.
Upvotes: 1
Views: 3383
Reputation: 751
Look at the "overflow" property in CSS: https://developer.mozilla.org/en-US/docs/CSS/overflow
This will allow you specify how your outer container handles the size of its content.
Upvotes: 0
Reputation: 16675
All you need to do is specify the height
of your container and the overflow
method:
HTML
<div class="container">
<!-- content here -->
</div>
CSS
.container {
height: 400px;
overflow-y: scroll;
}
Upvotes: 1
Reputation: 877
Try this it will work HTML
<div id="main_div">
// Your contents
</div>
CSS
<style type="text/css">
#main_div {
width:200px;
height:400px;
overflow:scroll;
}
// stylish scroll bar
#main_div{
overflow: scroll;
}
#main_div::-webkit-scrollbar {
background: transparent;
height: 4px;
overflow: visible;
width: 4px;
}
#main_div::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.9);
-webkit-border-radius:5px;
}
#main_div::-webkit-scrollbar-thumb:hover{
background-color: rgba(0, 0, 0, 0.6);
}
#main_div::-webkit-scrollbar-corner {
background: transparent;
}
</style>
Upvotes: 1