本文主要给大家介绍了利用css3如何设置没有上下边的列表间隔线,文中分享了两种解决方法,分别是利用通用兄弟选择器( ~ )和伪类选择器( :first-of-type / :last-of-type )来实现的,给出了详细的示例代码供大家参考学习,下面来一起看看吧。希望能帮助到大家。
效果图:

方法一:通用兄弟选择器( ~ )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!DOCTYPE html>
<html lang= "en" >
<head>
<meta charset= "UTF-8" >
<title>Document</title>
<meta name= "viewport" content= "width=device-width" >
<style>
ul {margin: 0; padding: 0;}
li { list-style: none; height: 50px; line-height: 50px;}
li~li {border-top: 1px solid #000;}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</body>
</html>
|
登录后复制
li~li {...} 中的 ~ 符号称为通用兄弟选择器,匹配P元素之后的P元素,所以第一个P元素不会匹配到。
方法二:伪类选择器( :first-of-type / :last-of-type )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!DOCTYPE html>
<html lang= "en" >
<head>
<meta charset= "UTF-8" >
<title>Document</title>
<meta name= "viewport" content= "width=device-width" >
<style>
ul {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;}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</body>
</html>
|
登录后复制
首先将所有 li 设置 border-top,然后用 :first-of-type 查找到第一个 li ,取消border-top。
相关推荐:
CSS3实现逐渐发光的方格边框实例
用CSS3优化HTML5表单的步奏
CSS3里怎么实现单选框动画特效
以上是css3设置没有上下边的列表间隔线方法实例的详细内容。更多信息请关注PHP中文网其他相关文章!