Say I have a list as follows:
- item1
- item2
- item3
Is there a CSS selector that will allow me to directly select the last item of a list? In this case item 3.
Cheers!
Say I have a list as follows:
Is there a CSS selector that will allow me to directly select the last item of a list? In this case item 3.
Cheers!
Not that i'm aware of. The traditional solution is to tag the first & last items with class="first" & class="last" so you can identify them.
The CSS psudo-class first-child will get you the first item but not all browsers support it. CSS3 will have last-child too (this is currently supported by Firefox, Safari but not IE 6/7/beta 8)
Until it's properly supported, you'll need to add a class to 'last' items, as suggested. You don't have to do this manually, though. If you can take a javascript hit, take a look at either:
Either will avoid 'polluting' your markup, and are perfectly acceptable if your style is a 'nice addition' as opposed to a 'must have' design feature.