Home arrow Style Sheets arrow Page 3 - Rediscover the Hover CSS Pseudo-Class
STYLE SHEETS

Rediscover the Hover CSS Pseudo-Class


In this introductory article in a four-part series, I provide you with an elementary but illustrative example that shows how to use the “hover” CSS pseudo-class for highlighting different sections of an (X)HTML document.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
December 17, 2009
TABLE OF CONTENTS:
  1. · Rediscover the Hover CSS Pseudo-Class
  2. · Building a sample (X)HTML page
  3. · Defining some simple CSS styles
  4. · Putting all the pieces together

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Rediscover the Hover CSS Pseudo-Class - Defining some simple CSS styles
(Page 3 of 4 )

 

If you’ve ever used the “hover” CSS pseudo-class before for creating fancy navigation bars or rollover effects on hyperlinks, then you’ll find the following CSS snippet easy to grasp. It uses the same driving logic, but in this case for changing the background color of the sections of the web page created in the previous segment.

Now, take a look at the styles below:

<style type="text/css">

body {

padding: 0;

margin: 0;

background: #eee;

font: 1em Arial, Helvetica, sans-serif;

color: #000;

}

#wrapper {

width: 960px;

margin: 0 auto;

background: #fff;

}

 

/* style header section */

#header {

padding: 20px;

}

#header:hover {

background: #c0ffc0;

}

 

/* style content section */

#content {

padding: 20px;

}

#content:hover {

background: #c0ffc0;

}

 

/* style footer section */

#footer {

padding: 20px;

}

#footer:hover {

background: #c0ffc0;

}

</style>

Apart from applying a basic style to the entire XHTML document, the above code sample shows how easy it is to create a rollover effect on each of its sections. In this particular example, the “hover” state of the sections switches to a different background color, but as you may guess it’s possible to apply all sorts of style variations, such as adding borders, changing background images and so forth. For obvious reasons, the most relevant detail to notice here is unquestionably the use of the “hover” pseudo-class with divs, which used to be impossible to accomplish due to the IE-related incompatibility discussed at the beginning.

Well, at this point I’ve partially reached the goal that I imposed on myself for this introductory article: on one hand, there’s a basic, text-based web page made up of the classical header, content and footer sections, while on the other, there are the CSS styles that create a rollover effect on these sections.

So, what’s the next logical step? Yes, you guessed right! Naturally, it’s necessary to link these two layers to each other to finish this example and get it ready for testing. 

This will be done in the last section of this tutorial, so read the next segment. It’s only one click away.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials