views:

47

answers:

3

Hi all

Maybe the title of this question is ambiguous, what I really mean is:

#footer_list li a:link, #footer_list li a:visited
{
    blah balh blah
}

Is there a shortcut for the two elements in CSS? so the CSS selectors can be shortened

+2  A: 

Sure. If you give them each their own respective class/id names. But thats unnecessary. The code you have is perfectly acceptable, as CSS is Cascading Style Sheets, the rules cascade down essentially.

Russell Dias
@Russell Dias: whenever I type/paste something "redundant" I always think I must do it in a wrong way :(
Michael Mao
Not only are classes unnecessary, but they don't work as they can't substitute pseudo-classes. (I'm just giving a friendly expansion on your answer here though.)
BoltClock
@Michael Mao: Questioning things is a good trait to have. But, don't automatically assume its the wrong way. If it works, then use it. *this should be taken with a grain of salt*
Russell Dias
+1  A: 

Your code is fine as is. I've been styling my sites with selectors like that and it hasn't bothered me or the browsers.

If your server runs Ruby and you don't mind picking up a server-side "extension" to the standard CSS syntax, LESS provides nested rules so you can do something like this:

#footer_list li {
    a:link {
        /* Styles for normal links */
    }
    a:visited {
        /* Styles for visited links */
    }
}

OK, I'm not sure what differences this will make, but I'm sure it'll be treated differently by browsers:

#footer_list li a {
    /* Styles */
}

You can then place additional a selectors with classes or a:hover or a:active below that and they'll work when applicable.

BoltClock
@BoltClock : WOW! that's something I didn't know... I will check this out with my hosting server and see if I can do this there :)
Michael Mao
@Michael Mao there is also http://sass-lang.com/
Russell Dias
@Michael Mao: I updated my answer again. See if the last (LESS not needed) selector works for you.
BoltClock
Oh delicious nested CSS selectors. I can't figure out why CSS isn't nested when it's designed to style (X)HTML, the most insanely nested thing ever conceived of.
meagar
@meagar: you're right! Now I'm left wondering too...
BoltClock
A: 

Do you have links within #footer_list that aren't within li elements? Do you have any other lists within your footer?

I'm imagining you have something like this in your markup:

<div id="footer">
    <p>&copy; me 2010</p>
    <ul id="footer_list">
        <li><a href="/home">Home</a></li>
        <li><a href="/contact">Contact</a></li>
        <li>....
    </ul>
    <p>Some other text...</p>
</div>

In this case your rule only needs:

#footer a:link, #footer a:visited

If you do (or might later) have links outside the ul which you want to style differently you could do:

#footer_list a:link, #footer_list a:visited
robertc