tags:

views:

215

answers:

4

Hello all, I have a annoying problem .. I want my first 4 items in a list to be numbered but I wanna leave fifth item out of numbering .. here is my css :

#alternate_navigation ol
{
    display:block;
    padding:0;
    margin:0;
    counter-reset: item;
}

#alternate_navigation li
{
    display:block;
    padding:0px 0px 0px 10px; 
    margin:0;
    background: url('images/list_bg.jpg') no-repeat;
    height:19px;
    width:99%;
    border-bottom:1px solid #B9B5B2;
}

#alternate_navigation li:before 
{ 
  content: counter(item) ". "; 
  counter-increment: item ;
}

RESULT :

  1. Online Booking
  2. Coupon Ordering
  3. Print Letters
  4. Send Emails
  5. View orders

How could I achieve for last item not to be numbered like this :

  1. Online Booking
  2. Coupon Ordering
  3. Print Letters
  4. Send Emails
    View orders

and yes HTML

<div id="alternate_navigation">
                   <ol>
                   <li><a href="#">Online Booking</a></li>
                   <li><a href="#">Coupon Ordering</a></li>
                   <li><a href="#">Print Letters</a></li>
                   <li><a href="#">Send Emails</a></li>
                   <li><a href="#">View orders</a></li>
                   </ol>
                   <div>

Thank you for any response

+1  A: 

After your current CSS, add:

#alternate_navigation li:last-child:before {
    content: "";
    counter-increment: none;
}

That should 'reset' the style for the last element.

EDIT: I should just mention that this will not work in IE8 due to the use of :last-child. If you need IE6/7/8 compatibility, I would use something like JQuery instead of manually inserting HTML markup.

Nick Presta
Why the downvote?
Nick Presta
It's "last-child" actually, and it's not supported by IE and Safari
yoda
check http://www.quirksmode.org/css/contents.html
yoda
thank you it works !!!
c0mrade
@yoda: I do have last-child, whereas your answer only has 'last', and since he is using counters and the :before pseudo-element, cross compatibility must not be high on the OP's list.
Nick Presta
c0mrade, you can please give feedback about browser support on this sollution, we'd be appeciate.
yoda
@Nick Presta, notice ".last" in my code as a class, not a pseudo-element .. Classes are recommended to avoid browser incompabilities in CSS, and since IE doesn't really support that feature, it's highly recommended. Nothing agains your sollution, I'd love if it works on IE :)
yoda
Well, not to care about a popular browser like IE seems stange to me, but since he didn't complain yet, I've got nothing more to say :)
yoda
I don't understand the need of using JQuery to do the job when you can use a class, as mentioned in my example, and wich works in IE8 ..
yoda
Because it introduces manual markup that has to be maintained and really isn't semantic HTML. Using JQuery, you can grab the last LI element and apply these properties.
Nick Presta
writting 10 chars in the markup is a lightweight sollution, instead of loading a fw like jquery just to do that.
yoda
He probably already has a JavaScript framework loaded already. Most professional (and hobbyist) developers use JQuery/Moo Tools/etc anyways. At any rate, the OP hasn't given more information and has marked this as accepted so I have no further reason to suggest things for a hypothetical situation.
Nick Presta
+1  A: 

Hi,

You can aplly a css class to reset that counter, like this example :

#alternate_navigation li.last:before
{ 
  content: ""; 
  counter-increment: none ;
}

Check my example :

http://www.aeon-dev.org/tests/before_pseudo_ie.html

yoda
+1  A: 

Is it possible that the browser you are using doesn't support content, counter-reset, :before, or counter-increment?

I'm pretty sure IE doesn't, and I'm not certain about others. If that is the case, you're just recieving the default numbered list: in short, the browser would ignore the newer CSS.

Eric
He is obviously seeing the numbers, as his 'Result' section shows them.
Nick Presta
Nick Presta, that doesn't mean he's seeing the expected result on IE, since we don't know what browser he's currently using.
yoda
A: 

Out of curiousity, in this case why are you using the counter-reset at all? Why not set

list-style: decimal;

and then for your html add a class to your last <li> tag like <li class="last">?

Then you can set

li.last { list-style: none; }
Jason Rhodes