Quick fix for strange CSS link behavior

by orangeacid on February 13, 2007 at 1:18 am

Posts on GTD and photography for Scenes and Emos in the pipeline, but just a quick update - something that I discovered working on a website for a school project earlier. If you’re not into webdesign, give this one a miss.

If you’ve any experience in semantic webdesign/xHTML+CSS, you will know how… well, frankly what an arse IE is to code for. One of my pet hates is the way that it handles the :hover pseudo class. Firstly, it only works on links, and secondly, I personally have encountered a large number of seemingly unexplainable errors that occur after the link has been followed.

First, some background theory.  The order of a CSS document is important - if two styles for an element exist, the last property will always win. Because of this, it is important to put your pseudo classes in the right order. This order is:

  1. :link
  2. :visited
  3. :hover
  4. :active

It is easy to remember this if you remember that you will have a love/hate relationship with pseudo classes - that’s link visited hover active.

This is fair enough, but sometimes certain properties won’t work after the link has been followed in IE<7.

OK. So, the solution?

Leave off the :link pseudo class. Your styles will work (as far as I can tell) just fine, without the strange, seemingly random errors. If in doubt, add a blank and pseudo-classed selector for each link.

Posted in Geekery, Site News.

Discussion

  1. Comment by RaymonWazerri on April 21, 2007 at 12:43 am

    Hey,
    I love what you’e doing!
    Don’t ever change and best of luck.

    Raymon W.

  2. Comment by moley on July 9, 2007 at 11:34 pm

    hmmm, so this seems a fiting time to advertise

  3. Comment by moley on July 10, 2007 at 6:39 pm

    fuck you psp inter net browser!

    i meant to say

    “hmmm, so this seems a fiting time to advertise firefox”

Leave a comment

Be friendly. Add a comment below.



*orangeacid.net uses Gravatars for comments.
Basic (x)HTML is allowed.