How do I have a border-bottom on all except the last item

后端 未结 4 1984
遥遥无期
遥遥无期 2021-02-02 08:09

If i have a ul, how do i set a border-bottom on all the li items except the last one? I\'m also trying to make the width of the border 180

4条回答
  •  情话喂你
    2021-02-02 08:38

    One way: You can override for the last one using a rule like below with :last-child (Since you tagged css3):

    .sideNav li:last-child a {
        border-bottom:0px; /*Reset the border for the anchor of last li of this ul*/
    }
    

    Demo

    There are polyfills available for IE8, but if you can provide a classname for the last one and apply rule to it to reset the style would be of better support, rather than using css3 (if your intention is to support older browsers as well).

    if you are using scripting language like jquery you can easily add a class to the last child as jquery takes care of cross-browser compatibility.

提交回复
热议问题