Submit Your Article
Home Articles News Tutorials Videos Add An Article
Topics: Design Photoshop Programming PHP CSS Java Database Web Development Javascript Ajax
– Close + Open

Find Out More About DevWebPro!

Sign up for the newsletter


» Terms & Conditions

Welcome to the New DevWebPro!

DevWebPro Includes:
  Hundreds Of Tutorials   Developer News
  Unique Gadget Videos   Tons of Topics to Discuss
  Expert Advice   We Will Publish Your Articles

Rollovers using only CSS

By: Derald
Tuesday, May 20th, 2008
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook

In the past we have posted on how to create rollovers using CSS. To do this, we used a sprite to create the rollover effect. You can also create a rollover effect by using just CSS.

Let’s first look at the CSS code that will allow us to create this effect.

<style>
.menu a:hover {
display: inline;
color: #3979ba;
background-color: #76b71a;
font-weight: bold;
padding: 5px;
}
.menu a{
display: inline;
color: #76b71a;
background-color: #3979ba;
font-weight: bold;
padding: 5px;
}
.menu li{
display: inline;
}
</style>

So far we have uses the pseudo-class :hover, and applied the effect to any a tag with in the menu class. What we did with the :hover is invert the colors of the text and background, everything else says the same. If the other attributes did not stay the same the rollover effect would not look proper. We also make all the li elements display in a row with the inline attribute.

Now for the HTML code

<ul class=”menu”>
<li><a href=”#”>Link 1</a></li>
<li><a href=”#”>Link 2</a></li>
<li><a href=”#”>Link 3</a></li>
</ul>

As you see the HTML code is just an unordered list that has the class menu applied to it. In each list element, we have a link for our menu.

Topics: , ,

About the Author:

Leave a Comment

DevWebPro is an iEntry Network ® publication - © 1998-2010 All Rights Reserved