As all CSS users should know, the :hover pseudo state is sweet, but has its limitations. :hover pretty much works on all elements, and in the future, it should work on all elements in all browsers. However, right now, we still have to deal with Internet Explorer 6 and the fact that :hover only works on links.

Typically, I have to beat IE into submission, and that was still the case with my most recent redesign, version 3. Okay, lets set up a scenario where we will need to use more than the link for a hover action. Lets say we are using the ohh so popular rounded box technique, but we don’t want the box to have a static height. Basically, heres what we want: A normal link with a bunch of content in the box. The box will be a fixed width, but a variable height. When the user hovers over the link, we want a rounded box to show.

So lets start off. Here is our link with a bunch of text in it:


When an evil darkness enshrouds the land of Hyrule, a young farm boy named Link must awaken the hero – and the animal – within. When Link travels to the Twilight Realm, he transforms into a wolf and must scour the land with the help of a mysterious girl named Midna.

And here is the code for the link (very basic):

<a class="big-link" href="..." title="...">
...
</a>

Pretty simple so far. Lets add some CSS:

CSS:

a.big-link{
display:block;
width:160px;
padding:5px;
border:none;
}

Lets see what that CSS has done for us:


When an evil darkness enshrouds the land of Hyrule, a young farm boy named Link must awaken the hero – and the animal – within. When Link travels to the Twilight Realm, he transforms into a wolf and must scour the land with the help of a mysterious girl named Midna.

Alright, so now lets add the CSS to make the rounded corners appear when we hover. I am using a very special image. It happens to be just the white rounded corners, but it is a transparent gif. That way, any background color will shine through.

a.big-link{
display:block;
width:160px;
padding:5px;
border:none;
}
a.big-link:hover{
background: #eeeeee url(/style/images/nav_list_alt_top.gif) left top no-repeat;
}

Check it out and try to hover the text below:


When an evil darkness enshrouds the land of Hyrule, a young farm boy named Link must awaken the hero – and the animal – within.

Great! However, we only have half of the effect that we need. We need to have another image for the bottom and we need that to change out on hover as well. The trick is to put another tag within the link. This way the :hover pseudo state can be used to affect that tag:

Here is the modified XHTML:
<a class="big-link" href="..." title="...">
</span>
...
</span>
</a>

Here is the modified CSS:
a.big-link{
display:block;
width:170px;
padding:0px;
border:none;
}
a.big-link:hover{
background: #eeeeee url(/style/images/nav_list_alt_top.gif) left top no-repeat;
}

a.big-link span{
padding:5px;
display:block;
}
a.big-link:hover span{
background: url(/style/images/nav_list_alt_bottom.gif) left bottom no-repeat;
padding:5px;
display:block;
}

And here is the result:

When an evil darkness enshrouds the land of Hyrule, a young farm boy named Link must awaken the hero – and the animal – within.

Voila! It works. Now, we are using the :hover pseudo state to affect both the <a> tag and the <span> tags. But, the whole purpose of this was to allow for an adjustable height. So, lets see some different sizes using this technique:

Small:
This is why I stopped eating Chinese food…

Bigger:
He runs, he jumps, he…sings? And that’s just the beginning of the bizarre in this video. Carl Lewis at his best. This video rules.

Even Bigger:
A New Legend is Born: When an evil darkness enshrouds the land of Hyrule, a young farm boy named Link must awaken the hero – and the animal – within. When Link travels to the Twilight Realm, he transforms into a wolf and must scour the land with the help of a mysterious girl named Midna. In the Wii version of the game, The Legend of Zelda: The Twilight Princess delivers incredibly precise aiming control using the Wii remote. The Wii Remote and the Nunchuk controller are used for a variety of game activities, including fishing and special sword attacks. Players ride into battle against troops of foul creatures using an amazing horseback combat system, then take on massive bosses that must be seen to be believed.

Comments

16 Comments

  1. BillyG said over 4 years ago

    That’s pretty neat Komodo, thx for pointing that out for us.

  2. Philipe said over 4 years ago

    There’s another method which doesn’t require any additional markup.
    The explenation: http://standards.webmasterpro.de/index.html?article=runde-boxen
    …and the demo: http://standards.webmasterpro.de/data/upload_runde-boxen_1126429578_beispiel.html

  3. Rogie said over 4 years ago

    @Philipe: This method does NOT work in Internet Explorer. Also, when you resize the text, the technique breaks. If I didn’t know any better, I’d say this technique sucks. ;)

  4. Ben McNelly said over 4 years ago

    nice…

  5. Enrique said over 4 years ago

    Great! Really thanks! ;-)

  6. Dave said over 4 years ago

    @twdizu: wow, inspiration to us all! i’ll think about that one, definately.

  7. darkbop said over 4 years ago

    Awesome tutorial!. Tanks.

  8. Nguyen Vu said over 4 years ago

    WOW! Very usefull to me! Thank you :)

  9. kmwaegvdo said over 3 years ago

    free gay porn…

    idqkzvjxe navqnwyhy btnzloeuje zwhhxsqy jepkaoedm vgdupksg qfjjxqubmm uvduqfftxy…

  10. hwoeukzvpk said over 3 years ago

    mature…

    wdovmwekg rlghsjmtbpe vziutch vufnigqqiq nbjbjis ilylmqhqaw ovlqxqmn gmymxwdao…

  11. Ian said over 3 years ago

    In reply to Rogie who said that this technoque does not work in IE. I’m viewing it now in IE6 and it works perfectly. Same in Firefox 2.

  12. Ian said over 3 years ago

    In reply to Rogie who said that this technoque does not work in IE. I’m viewing it now in IE6 and it works perfectly. Same in Firefox 2.

  13. dhmmjckdk said over 3 years ago

    nice ass…

    sljqdrhq roaaexzg bsvrhmtc ibtobkodew uapztxxjmoi mfoxer jdcgw cndlifvg…

  14. Beto said over 2 years ago

    It works 4 me in IE and Firefox :)

    Thanks a lot, nice work.

  15. Marco said over 2 years ago

    Oi! This doesn’t seem to work anymore…

  16. el lu said over 2 years ago

    yeap, it doesn’t work

Sorry, the comment form is closed at this time.