PDA

View Full Version : CSS Scroller - Article


ranjan
12-01-2004, 01:59 PM
The objective of this article is to build a cross browser CSS Scroller that degrades in older browsers.

Required HTML

The HTML required for building the scroller is, just a div with contents in it.
HTML Code:

<div id="Scroller">


Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus non turpis. Aenean ullamcorper dui ut velit. In sem orci, convallis id, mollis ac, pharetra et, leo. Integer nunc eros, rhoncus eu, lobortis at, facilisis consectetuer, nunc. Ut ut risus dapibus arcu porttitor imperdiet. Donec vehicula enim vel orci. Fusce porta egestas elit. Sed sollicitudin mauris in ante. Integer vitae lorem. Nam tincidunt.</p>


Ut aliquet ipsum. Aenean dictum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec sodales velit eu sem. Nam commodo commodo neque. Quisque gravida pharetra ante. Nulla consectetuer. Sed cursus adipiscing elit. Cras nibh nisl, tristique sed, tristique eget, commodo id, odio. Proin ultrices, elit eget scelerisque luctus, dui metus tristique est, non tincidunt velit risus id justo. Mauris egestas orci eleifend libero. Fusce pede. Cras sit amet tortor quis leo sollicitudin ultrices. Sed sem. Integer luctus, lacus eget dictum convallis, wisi tortor consequat mi, vel faucibus nulla pede in eros. Nunc dapibus aliquam enim. Integer est mauris, feugiat quis, scelerisque ut, ullamcorper sit amet, tortor.</p>


Sed ultricies, magna ac euismod tincidunt, sem lectus consectetuer quam, a fermentum est tortor vitae felis. Sed sit amet libero. Curabitur non magna id erat aliquam faucibus. Vivamus dapibus. Nulla eu magna sit amet est placerat ullamcorper. Integer ac nisl eu odio ullamcorper ultrices. Suspendisse arcu nunc, posuere vitae, bibendum sit amet, accumsan at, nibh. Aliquam tristique dolor rutrum felis. In nulla. Maecenas nunc mi, molestie sit amet, consequat eu, aliquam sed, orci. Pellentesque varius. Donec ut erat nec quam volutpat ultricies. Proin non orci a dui dignissim faucibus. Donec faucibus tellus quis wisi. Phasellus dolor massa, blandit sit amet, mollis ac, sodales quis, diam. Donec risus odio, gravida et, pretium vitae, gravida id, turpis. Donec id libero vitae lorem tincidunt ultrices. Duis porta tincidunt erat. Suspendisse dapibus molestie tellus.</p>
</div>



The Required CSS

To position the above div you need to declare the following styles:

1. top - the top position of the div in pixels or %
2. left - the left position of the div in pixels or %
3. width - the width of the div in pixels
4. height - the height of the div in pixels
5. overflow - to make it scroll

HTML Code:

#Scroller {
position:absolute;
left:100px;
top:50px;
width:250px;
height:150px;
overflow: auto;
background: #CCCCCC;
padding: 5px;
}



The background and padding were added to make it look a bit better. You could add required styles for font, border, etc.

Styling the Scrollbars

IE 5.5 and above allows you to style the scrollbars. However this is proprietary to IE and doesnot validate unless you put them within IE Conditional statements

HTML Code:

<!--[if IE]>
<style type="text/css">
#Scroller {
scrollbar-arrow-color:#333333;
scrollbar-track-color:#CCCCCC;
scrollbar-face-color:#CCCCCC;
scrollbar-highlight-color:#FFFFFF;
scrollbar-3dlight-color:#FFFFFF;
scrollbar-darkshadow-color:#FFFFFF;
scrollbar-shadow-color:#FFFFFF;
}
</style>
<![endif]-->



Note: Opera 7.5+ allows users to choose to see custom scrollbars. However this is not a default setting. If you feel the need to make your scrollbars appear colored in Opera 7.5+, you would have to remove the if/end if IE conditional statements at the cost of sacrificing validity of the CSS

domedia
12-01-2004, 03:00 PM
Pretty Nice Ranjan!
If you have similar writings/articles msg me and we'll feature them as an article on this website.

I wrote some similar code some time ago called Scroll area with overflow in CSS ('http://www.domedia.org/oveklykken/css-div-scroll.php')

ranjan
12-01-2004, 11:50 PM
i have a few articles published at gthelp.com

http://gthelp.com/showthread.php?t=28136 ('http://gthelp.com/showthread.php?t=28136')
http://gthelp.com/showthread.php?t=33674 ('http://gthelp.com/showthread.php?t=33674')
http://gthelp.com/showthread.php?t=30804 ('http://gthelp.com/showthread.php?t=30804')
http://gthelp.com/showthread.php?t=30781 ('http://gthelp.com/showthread.php?t=30781')
http://gthelp.com/showthread.php?t=30805 ('http://gthelp.com/showthread.php?t=30805')
http://gthelp.com/showthread.php?t=30330 ('http://gthelp.com/showthread.php?t=30330')
http://gthelp.com/showthread.php?t=28142 ('http://gthelp.com/showthread.php?t=28142')

you could use any of those here if you find any interesting

domedia
01-18-2005, 02:07 AM
Ranjan,
I really like the contribution. I will take some time to see if I can feature them on this website as well.