what's the different between a and a:link?
Posted: Sun, 2008-05-18 13:28
I watch a wordpress theme and I feel a confuse about the code..
#nav ul li {
float:left;
margin:0px 1px 0px 0px;
padding:0px;
}
#nav ul li a {
color:#000000;
display:block;
padding:5px 7px 6px;
text-decoration:none;
}
#nav li a:visited {
color:#000000;
text-decoration:none;
}
#nav li a:hover,#nav .current_page_item a, #nav .current_page_item a:visited {
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
what's the #nav .current_page_item mean?
why the code need #nav .current_page_item ?


Enthusiast
Posts: 308
Joined: 2008-02-04
Location: Netherlands
a and a:link
Posted: Sun, 2008-05-18 13:54
Well the title of your question is what's the difference between a and a:link. a is all links. a:link is specifically untouched (uncached) links. :link, :hover and all other specific forms of a can override a's styles, in the order that they are listed in the css. a:link as far as I'm concerned is useless because, being a more specific form of a, it cannot pass down its styles to other a's (so if you wanted all links to be text-decoration: none, then don't set it on a:link or you'll just have to set it on every other sort of a too...)
Now, the question in your post is something differnet.
#nav ul li a {color:#000000;
display:block;
padding:5px 7px 6px;
text-decoration:none;
}
#nav li a:visited { <---extra
color:#000000;<---unneeded
text-decoration:none;<---bloatcode : )
}
The #nav ul li a is setting all the anchors (a) in the menu inside the element called #nav. For this reason, the a:visited part listed here is useless-- it will already be #000 (black) and not underlined anyway because it's already set for all anchors using "a".
#nav li a:hover,#nav .current_page_item a, #nav .current_page_item a:visited {background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
This part, the coder is overriding the basic styles for :hover so that the buttons or whatever they are look different when someone hovers. Makes sense. The other two look like a "You Are Here" style-- meaning that in the whole menu, there is a menu item that should always look hovered-- even if it's been visited before. So there's a class on a single menu item called .current_page_item showing the visitor which page they're on by giving that item a highlight.
To make that change with every page (since it should be on a different menu item on different pages), lots of people use an id on the body. body id="home" or whatever, then the Home button on the menu would have the current_page_item class on it, and would tell visitors that they were back on the Home page. For instance.
I'm no expert, but I can fake one on teh Interwebz
newbie
Posts: 3
Joined: 2008-05-18
#nav .current_page_item
Posted: Sun, 2008-05-18 15:06
#nav .current_page_item a{
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
but these code doesn't equal to below?
#nav .current_page_item a:visited {
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
#nav .current_page_item a:link {
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
#nav .current_page_item a:hover {
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
#nav .current_page_item a:active {
background:#2E91C6 url(nav-item-hover.gif) repeat-x scroll 0%;
color:#FFFFFF;
text-decoration:none;
}
if equal, why this need the #nav .current_page_item a:visited ?
#nav li a:hover,#nav .current_page_item a, #nav .current_page_item a:visited {
Enthusiast
Posts: 308
Joined: 2008-02-04
Location: Netherlands
Quote:but these code doesn't
Posted: Mon, 2008-05-19 04:17
They do, you are correct. You do NOT need all those declarations because "a" will make the rest the same. You only need to list :hover, :visited, etc. IF you want them different.
I think maybe you have all these extra declarations because this is a template. The writers of templates don't know what you will want to change, so they write all this extra code so that, if you wanted to change .current_page_item's :visited state, for example, then it's already there for you to edit.
But it's bloated code. This is why I don't like templates : ) They want to be flexible for the people who buy them. I want MY code to be lean : )
I'm no expert, but I can fake one on teh Interwebz
newbie
Posts: 3
Joined: 2008-05-18
thanks for Stomme poes effort
Posted: Mon, 2008-05-19 12:02
thanks for Stomme poes effort