1

I am trying to make the last category have no bottom border, is there is any trick to done it without programming?

HTML & CSS:

<style>
#menu {
  border:1px red solid;padding:10px
}
#menu a {
  display:block;
  border-bottom:1px #000 dotted
}
</style>
<div id="menu">
  <p>MAIN MENU</p>
  <a>Computers</a>
  <a>Design</a>
  <a>Programming</a>
</div>

EXAMPLE: http://jsfiddle.net/GLJWp/

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
Alaa Gamal
  • 1,135
  • 7
  • 18
  • 28

3 Answers3

3

Have a look at the :last-child pseudo class, which will apply the css rules only to the last item: http://www.quirksmode.org/css/firstchild.html

In this case you'd style the last link by:

#menu a:last-child {border-bottom:none}

For supporting IE <9, have a look at this beautifully horrible conditional stylesheet hack.

Community
  • 1
  • 1
Ben D
  • 14,321
  • 3
  • 45
  • 59
3

You may try this, because last-child doesn't work in IE

HTML

<div id="menu">
    <p>MAIN MENU</p>
    <a>Computers</a>
    <a>Design</a>
    <a>Programming</a>
</div>​

CSS

#menu{
    border:1px red solid;padding:10px
}
#menu a{
    display:block;
    border-top:1px #000 dotted
}

The following would effect the first a after the p, a:first-child won't work in IE because p is the first child element

#menu p + a{
    border-top: none;
}

DEMO.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
1

Done here: http://jsfiddle.net/GLJWp/2/

Whymarrh
  • 13,139
  • 14
  • 57
  • 108