In this tutorial I will describe the process of implementing text and image rollovers within list items using only HTML and CSS. No Javascript will be harmed in this tutorial! If you have no background in CSS, it would be beneficial for you to read my Beginners Guide to CSS
You can also learn more about the CSS list items used within this tutorial in my Guide to CSS and HTML Unordered Lists
First of all I would like to cover some basic background information regarding the accessibility of CSS rollovers. You don't need to fully understand the following information to use this tutorial, this is just a heads up to help you understand the other ways you may be able to utilize CSS, and assist you in grasping the concepts more fully.
To date, cross-browser rollovers can only be assigned to the link element within your CSS. This is the text/image held within or by the tag.
The examples I am going to use as CSS selectors are called Pseudo-Classes. These selectors are used to add some different and more advanced effects to your HTML web page. You can learn more about all of the Pseudo-Classes and their compatibility at the W3Schools CSS Link
This tutorial is only going to use the Anchor Pseudo class element. Anchor Pseudo class elements can only be used on the 'a' element of your CSS, but in CSS2 (which is not currently cross-browser capable), you can use many more selectors as Anchor Pseudo Class elements. Now, on to the tutorial.
1. Create a new HTML document, with all of the necessary DOD, head and body tags.
In this tutorial, we are going to place the CSS code inside the head portion of the document, as opposed to attaching it separately.
2. Start by creating the basic HTML of the list elements that we are going to create rollovers for.
Home
About Us
Products
Contact Us
This is a simple navigation list example, because the majority of rollovers are used for navigation or links. The entire navigation is held within a div container titled "mynavigation." The ul element is defined by the ID element "navmenu." The next example has the CSS and it should clarify any confusion that you might have. You can use your imagination through this tutorial if you want to apply rollovers to other 'a' elements.
3. Creating the CSS
The styles will go in between the portion of your document.
#mynavigation {
width: 200px;
}
#mynavigation ul {
margin-left: 0;
padding-left: 0;
list-style-type: none;
font-family: verdana;
}
#navmenu a {
display: block;
padding: 3px;
width: 160px;
background-color: #000000;
border-bottom: 1px solid #ffffff;
}
#navmenu a:link, #navmenu a:visited {
color: #ffffff;
text-decoration: none;
}
#navmenu a:hover {
background-color: #D5D0CD;
color: #6D7A73;
}
This is going to create a box, 200px in width around the entire navigation. Each link (between the elements) is displayed as a block, with a background color of black, and text color of white. The rollover state will produce different colors for the background of the block and the text color, shades of grey are used in this example. The Anchor Pseudo-Class elements are
- a:link - Applies the style to a link that has not been visited
-
-
a:visited - Applies the style to a link that has already been visited
-
- a:hover - This is where your rollover comes in. This style is only applied when the user rolls their mouse over the link.
-
- This is where your rollover comes in. This style is only applied when the user rolls their mouse over the link.
In this case, when the user rolls over the link with their mouse, the background color of each link and the link text will change color. You can see an example of the two states of the links in the picture supplied. Experiment with different colors, try it for yourself in a simple .txt document or in your favorite web page design software.
This is a basic example of using rollovers to enhance your web page. You can apply these rollovers to any element, and you should experiment with different colors, styles and sizes on your own.
Published by Nikki Freeman
Freelance Writer, Graphic Designer, Web Designer. My first passion was writing, my second Art, my third singing/songwriting/music/my guitar, fourth technology. Put them all together and somehow they manage t... View profile
Defining Width: How to Make Your Site Cross-Browser FriendlyStart with how wide your pages need to be in order to be viewed by the widest range of monitors and browsers before you draw a single block or code a single line, and your websi...
Which is the Best Browser for You?Internet Explorer, Mozilla Firefox, Netscape and Opera are all out to convince the world that theirs is the best. When compared, which comes out on top? - Photoshop Tutorial: How to Create Glamor PhotosGive your photos a glamorous twist with this Photoshop Tutorial.
- Photoshop Tutorial: How to Cut and Put Images on a Transparent BackgroundIn this Photoshop tutorial you will learn how to cut images and place them on a transparent background. This is a great tutorial for beginners.
Photoshop Tutorial: Learn How to Create Chat Bubble Icons or Web GraphicsIn this Photoshop tutorial, you'll learn to create chat bubble icons that can be used on your website or Myspace.
- Styling CSS and HTML Unordered Lists
- A Guide to Understanding Cascading Style Sheets Within Web Design
- Building a Basic CSS Menu
- Top 3 Automatic CSS Creators
- How to Create Custom Tooltips with Just HTML and CSS
- Pseudo-Classes
- Web Standards, Semantic Markup and Cross-Browser Compatibility
- Beginners Guide to CSSStyling CSS and HTML Unordered ListsW3Schools CSS LinkCSS2 Reference
- CSS Rollovers are created using the Anchor-Pseudo Class Element
- No Javascript is harmed in this tutorial
- CSS Rollovers need to be contained within the link tags

