Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,058 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,553 people online right now. Registration is fast and FREE... Join Now!




mouseover effect using only CSS

 
Reply to this topicStart new topic

mouseover effect using only CSS, I cant get this working! need some help :)

VIonescu
20 Jul, 2008 - 04:46 PM
Post #1

New D.I.C Head
*

Joined: 20 Jul, 2008
Posts: 24


My Contributions
Hey all, I've run into a bit of a problem.

I'm designing a website for a customer, and I'm trying to make a rollover effect using only CSS. No DHTML or JS plz tongue.gif
I learned this was possible using an image thats twice as high as you specify in the stylesheet, so this way only half the image is showing and by editing the CSS for anchor links (a:link and a:hover) in the following manner you can change which half of the image shows while its active and while its in its normal state (hope this makes sense...):
css
li {
display: block;
width: 100px;
height: 50px;
text-indent: -9999px;
}

li a {
background: url(button.png) no-repeat bottom center;
}

li a:hover, li a:active {
background: url(button.png) no-repeat top center;
}


HTML
<li><a href="#">gibberish</a></li>


So anyways, thats supposed to work in theory...and it does. Its just not working for me sad.gif

Here is my code, does anyone see anything wrong with it? I've been hacking away at it for hours all to no avail....
HTML
<ul id="nav">
<li id="home"><a href="#">home</a></li>
<li id="our_work"><a href="our_work.html">our work</a></li>
<li id="about"><a href="about.html">about</a></li>
<li id="contact"><a href="contact.html">contact</a></li>
</ul>

css
ul#nav {
width: 760px;
height: 165px;
background: url(images/nav-bg.png) no-repeat bottom right; /*THIS IS JUST A BACKGROUND TO MY NAV MENU, IGNORE THIS */
}
ul#nav li {
display: inline;
}
ul#nav li a {
display: block;
margin-top: 114px;
height: 51px;
text-indent: -9999px;
float: left;
}
ul#nav li#home a {
width: 104px;
background: url(images/nav-home.png) no-repeat bottom center;
}
ul#nav li#our_work a {
width: 134px;
background: url(images/nav-our_work.png) no-repeat bottom center;
}
ul#nav li#about a {
width: 107px;
background: url(images/nav-about.png) no-repeat bottom center;
}
ul#nav li#contact a {
width: 185px;
background: url(images/nav-contact.png) no-repeat bottom center;
}
ul#nav li a:hover {
background-position: top center;
}


Note: The buttons are of varying horizontal sizes (thus the different width's specified for each button) but they are all exactly 102px tall. The "off" or normal state is at the bottom of the image, and the "on" or mouseover state is at the top of the image.

Much thanks to who ever can help me out smile.gif

This post has been edited by VIonescu: 20 Jul, 2008 - 04:59 PM
User is offlineProfile CardPM
+Quote Post

djkitt
RE: Mouseover Effect Using Only CSS
21 Jul, 2008 - 07:11 AM
Post #2

D.I.C Head
**

Joined: 22 May, 2008
Posts: 128



Thanked: 13 times
My Contributions
Hey there,

Try making a unique hover for each of your <li> ids, like so:

CODE

ul#nav li#home a:hover             
{
    background-position: top center;        
}


Hope rhis helps...
User is offlineProfile CardPM
+Quote Post

VIonescu
RE: Mouseover Effect Using Only CSS
21 Jul, 2008 - 08:00 AM
Post #3

New D.I.C Head
*

Joined: 20 Jul, 2008
Posts: 24


My Contributions
Yeah Ill try that smile.gif

EDIT:
bwah...I dunno, I tried specifying them individually yesterday and it didn't work, but after much more fiddling I figured that I had to specify all the parents to the a:hover selector. Here is what finally fixed it:
css
ul#nav li#home a:hover, ul#nav li#our_work a:hover, ul#nav li#about a:hover, ul#nav li#contact a:hover {
background-position: top center;
}


This post has been edited by VIonescu: 21 Jul, 2008 - 09:36 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:10PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month