|
|
CSS Scrollbar - color scrollbar using cascading Style SheetsColors can be added to the otherwise "dry" web page scrollbar using CSS (Cascading Style Sheets). The colored scrollbars are visible in Internet Explorer (version 5.5+); other popular web browsers like Firefox, Opera and Netscape do not display colored scrollbars because they ignore the scrollbar CSS code. So you do need Internet Explorer 5.5 or higher to see the scrollbar colors and take full advantage of this tutorial. Basic CSS property for a scrollbar - adding a base colorA quick way to color a scrollbar is to attach a base color to it. This is done using the scrollbar-base-color style sheet property which looks like:
{scrollbar-base-color: [color name]/[color value]}
Here is a page with an orange colored scrollbar - opens in a new window. The code used for this orange color is #FF9900 - Let us now have a look at a dark blue colored scrollbar - Click to display a web page that shows scrollbars using the css scroll-base-color property set to #003366 - Adding CSS code on web pages to color scrollbarsThere are two ways to attach this Cascading Style Sheets code to a web page - Embedding or Including/Importing an external .css file.
html {scrollbar-base-color: color name or color value}
This style is added to a web page either as an embedded style sheet or as an external style sheet (.css) file that is included on a web page using the HTML <link> tag or @import. If you haven't used style sheets ever, no need to worry... details are below. Embedding CSS scrollbar rule on a web pageStyle sheet rules can be embedded inside each web page in the <head> section enclosed within the <style> - </style> tags. So to create an orange colored scrollbar for a web page you use the following code:
<html>
<head>
<title>Your web page title</title>
<style type="text/css">
<!--
html {scrollbar-base-color: #FF9900}
-->
</style>
</head>
</body>
Your web page content
</body>
</html>
The style sheet rule is embedded in the HTML <style> tags and the html selector encloses the scrollbar-base-color property that has been set to #FF9900 value. Using external style sheet filesIf you use external style sheets on your web site then you can add the CSS rule to it. External CSS files are plain text ASCII files that contain style sheet rules and carry the file name extension .css. They can be embedded inside web page using the <link> HTML tag. <html> <head> <title>Your web page title</title> <link rel="stylesheet" href="the_style_sheet_file_name.css" type="text/css"> </head> </body> Your web page content </body> </html> Note: the <LINK> tag does not have a closing tag.
html {scrollbar-base-color:#FF9900;}
body {margin:0; padding: 0;}
H1 {font-family: Arial, Verdana, Sans-serif; color: #000099;
font-size: 20px; font-weight: bold;}
P {font-family: Verdana, Arial, Sans-serif; color: #000000;
font-size: 13px;}
Here I have specified style rules for the html, body, H1 and P selectors. Color scrollbars for other HTML elementsThe <TEXTAREA> in another HTML element that has scrollbars. We will now see how we can add color to scrollbars displayed by this element. Click here to view the page with css scrollbars for the TEXTAREA - (opens in a new window). The textarea has a light green scrollbar while the web page itself has a pink one. The style rules for this page are:
html {scrollbar-base-color: #FFC0FF;}
.ta {scrollbar-base-color: #D2E89E;}
The scrollbar-base-color property of the html selector puts a pink color on the main scrollbar of the web page. The other style rule .ta (note: a period prefixes the style rule) has the scrollbar-base-color property set to a light green color. <textarea class="ta" rows="4" cols="50">... </textarea> The values for cols and rows attributes can change depending on your requirements; but it's the class attribute and its value that are important for this discussion. Note that we set the value of this attribute to the style rule name and we don't include the period. Here is an interesting observation: Taking the above example, let us see what happens if we don't specify a style rule for a textarea scrollbars. Wasn't that simple? I hope with the several examples, you have got to know a little of style sheets if this was your first encounter with them. Since we are discussing style sheets, I will let you in on another property - background-color. This CSS property lets you add a background color to different HTML elements including web pages as a whole, form input elements, table cells etc. To add a background color to the textarea element that had the light green scrollbar (see above), we simply extend the style sheet rule to include this property.
.ta {scrollbar-base-color: #D2E89E; background-color: #EDF6D4;}
We have now added a lighter green color as the background for the textarea element. You can check how it looks - TEXTAREA with a background color and green scrollbars.
Page contents: CSS Scrollbar and how to add color to web page scrollbars using CSS (style sheets) color codes and properties.
Page URL: http://www.webdevelopersnotes.com/tips/html/ css_scrollbar_color_code.php3
|
|