CSS last-child selector: select last-element of specific class, not last child inside of parent?

前端 未结 6 784
夕颜
夕颜 2020-11-22 01:45
6条回答
  •  甜味超标
    2020-11-22 02:32

    :last-child only works when the element in question is the last child of the container, not the last of a specific type of element. For that, you want :last-of-type

    http://jsfiddle.net/C23g6/3/

    As per @BoltClock's comment, this is only checking for the last article element, not the last element with the class of .comment.

    body {
      background: black;
    }
    
    .comment {
      width: 470px;
      border-bottom: 1px dotted #f0f0f0;
      margin-bottom: 10px;
    }
    
    .comment:last-of-type {
      border-bottom: none;
      margin-bottom: 0;
    }
    hello

提交回复
热议问题