CSS :last-child 选择器选择指定class最后一个元素,为什么不对?

  写css的时候,经常需要选择一个类型的最后一个子元素,新手经常写成:last-child。

  而:last-child所指的是元素是容器的最后一个子元素,而不是特定类型的元素的最后一个子元素时才有效。

  我们可以使用:last-of-type来解决这个问题last-of-type

  代码如下:

  html

  hello

  css

  body {

  background: black;

  }

  .comment {

扫描二维码关注公众号,回复: 5573149 查看本文章

  width:470px;

  border-bottom:1px dotted #f0f0f0;

  margin-bottom:10px;

  }

  .comment:last-of-type {

  border-bottom:none;

  margin-bottom:0;

  }郑州人流医院

更多经验以后再交流。

猜你喜欢

转载自blog.csdn.net/q2834560049/article/details/88597736