这篇文章主要给大家介绍了利用css3如何设置没有上下边的列表间隔线,文中分享了两种解决方法,分别是利用通用兄弟选择器( ~ )和伪类选择器( :first-of-type / :last-of-type )来实现的,给出了详细的示例代码供大家参考学习,下面来一起看看吧。
本文主要介绍了关于利用css3如何设置没有上下边的列表间隔线的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍:
效果图:
方法一:通用兄弟选择器( ~ )
Documentul {margin: 0; padding: 0;}
li { list-style: none; height: 50px; line-height: 50px;}
li~li {border-top: 1px solid #000;}
- 1
- 2
- 3
- 4
- 5
- 6
li~li {...} 中的 ~ 符号称为通用兄弟选择器,匹配P元素之后的P元素,所以第一个P元素不会匹配到。
方法二:伪类选择器( :first-of-type / :last-of-type )
Documentul {margin: 0; padding: 0;}
li { border-top: 1px solid #000; list-style: none; height: 50px; line-height: 50px;}
li:first-of-type {border-top: none;}
- 1
- 2
- 3
- 4
- 5
- 6
首先将所有 li 设置 border-top,然后用 :first-of-type 查找到第一个 li ,取消border-top。
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐: