1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Does "a" override "a:link" "a:active" and "a:visited" in CSS ?

Discussion in 'CSS' started by lemony, Dec 11, 2007.

  1. #1
    Hi guys,

    Is there any difference between these two codes:

    
    a {
      color: #FF6600;
      text-decoration: none;
    }
    Code (markup):
    
    a:link, a:active, a:visited {
      color: #FF6600;
      text-decoration: none;
    }
    Code (markup):
    What I'm trying to understand is if the first code covers all the classes in that second code. So just specifying a style for the "a" tag would mean I don't have to also have tags for a:link, a:active, and a:visited.

    Thanks guys!
     
    lemony, Dec 11, 2007 IP
  2. manishk

    manishk Peon

    Messages:
    63
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Regarding your query: a will cover a:link and a:visited. Am not sure about a:active but I think it will be covered too.
     
    manishk, Dec 12, 2007 IP
  3. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As I understand it, a is broader (not as specific) as :link, :hover, etc.

    What most people do is look at what properties they want ALL their links to have, and give that to a.
    a:link is pretty much the same, but being more specific, its properties may not extend to the others.

    Let's say you have some links. You want ALL of them to not be underlined (the browser default). You want untouched links to be red, hover'd ones yellow AND bold, and active ones grey AND background colour white.

    So you set up the common attributes first:

    a {
    text-decoration: none;
    font: normal 1em/1.2em Verdana, Arial, sans-serif;
    text-align: center;
    color: #fbd302; (some sort of orange I think... I forget)
    }
    This sets your font and lack of underline, as well as placement and a default colour when none is specified.

    a:link {
    color: #f00; (red)
    }
    a:link is untouched links. You could also have set this in the a section as well... I don't think it matters. However, you wouldn't want to set all the other properties under a:link instead... I'm not sure but I dunno if the other pseudoclasses would inherit from a:link, just a.

    a:hover {
    font-weight: bold; (the default we set was normal)
    color: #ff0; (yellow)
    }

    a:active {
    color: #c7c7c7; (grey)
    background-color: #fff; (white)
    }

    I should test this first, but I believe that since I set the a colour to orange, the :visited may be orange since I didn't specify the :visited's colour, yet did specify the untouched :link colour. But, this only holds when I bother to mention :visited in the CSS in the first place. Notice I didn't mention :focus, so there is no orangey colour for :focus. If I mentioned :focus though without specifying a colour, then it would be orange.

    Eh, take my code and test it. You'll see who really has precedence. Also, all things being equal, the last thing mentioned will also have precedence. So, the a:active part will be seen even while the mouse is also hovering... if a:hover had been listed after :active, then :hover would "cover" :active because it's last in the CSS. If :visited comes after everything, :hover and :active shouldn't work (because even while hovering, the link is still "visited").

    *Edit, tested. http://stommepoes.jobva.nl/Tests/atest.html

    So yes, to answer your question, you can set all properties under a alone... and if you make any mention of the pseudoclasses, they will inherit from a whatever you don't specify.
    http://stommepoes.jobva.nl/Tests/atest2.html
     
    Stomme poes, Dec 12, 2007 IP
  4. lemony

    lemony Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hey Stomme_poes thanks for that detailed reply and for going the extra mile and putting up those test pages.

    That's exactly what I needed to know.

    I am "cleaning up" my CSS and removing all unnecessary coding so assigning properties to "a" instead of "a:link, a:active, and a:visited" will be my first step. Just wanted to be sure I wasn't going to screw anything up.

    Thanks for helping me out ;)
     
    lemony, Dec 12, 2007 IP
  5. JochenVandeVelde

    JochenVandeVelde Peon

    Messages:
    412
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A covers a:link, a:hover, a:active, a:visited, a:focus and all other pseudo-classes of a.
     
    JochenVandeVelde, Dec 14, 2007 IP
  6. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #6
    They're not psuedo-classes. They're psuedo-selectors. And "a" will only over-ride a:link (and so on) if it comes after the psuedo-selectors or if it's been given an !important over-ride.
     
    Dan Schulz, Dec 14, 2007 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #7
    Though it will INHERIT - which is what I think was being asked here.
     
    deathshadow, Dec 15, 2007 IP
  8. JochenVandeVelde

    JochenVandeVelde Peon

    Messages:
    412
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    They are selectors, but they're called pseudo-classes and they inherit.

    If W3C says it, they'll be right. No? http://www.w3.org/TR/CSS21/selector.html#pseudo-elements

     
    JochenVandeVelde, Dec 16, 2007 IP