CS3结构伪类选择器

在 CSS3 中的结构伪类选择器是选择父级标签下的子标签的最后一个子标签,但是在下述代码中标签dd 的子标签有三个 li 标签和一个a 标签 虽然 a 标签是dd 标签的最后一个子标签。我们预想 .timebook dd li:last-child 选择的是 dd 标签下的三个 li 标签中的最后一个,代码运行结果却没有达到想要的样式效果,将 a 标签注释掉发现达到了想要的效果,说明 .timebook dd li:last-child 选择的是 dd 的最后一个子标签 即是 a 标签。这里应该用 nth-child(n) 结构伪类选择器。选择最后一个 li 标签即 选择 dd 标签的第三个子标签。

总结:当父标签下有多个不一样的标签时,last-child 结构伪类选择器选择的是最后一个子标签 即使加上限制条件 也无法改变。

<div class="timebook">
    <dl>
	    <dt>我的课程表</dt>
		<dd>
		    <li>
			    <h5>继续学习 程序语言设计</h5>
			 	<p>正在学习-使用对象</p>
			</li>
			<li>
			    <h5>继续学习 程序语言设计</h5>
			 	<p>正在学习-使用对象</p>
			</li>
			<li>
			    <h5>继续学习 程序语言设计</h5>
			 	<p>正在学习-使用对象</p>
			</li>
			<a href="#" class="all">全部课程</a>
		</dd>
	</dl>
</div>
.timebook {
	width: 228px;
	height: 300px;
	position: absolute;
	right: 0;
	top: 50%;
	background-color: #fff;
	/*transform: translate(0, -50%);*/
	transform: translateY(-50%);
	/*但是 y 要大写才可以*/
}
.timebook dt {
	height: 50px;
	background-color: #9bceea;
	font-weight: 700;
	color: #fff;
	line-height: 50px;
	font-size: 18px;
	text-align: center;
	border-bottom: 1px solid #ccc;
}
.timebook dd {
	padding: 15px 20px 0;
}
.timebook dd li {
	height: 60px;
	padding-top: 6px;
	border-bottom: 1px solid #ccc;
}
.timebook dd li:nth-child(3) {
	border: 0;
}
/*.timebook dd li:last-child {
	border: 0;
}*/
.timebook h5 {
	font-size: 16px;
	font-weight: normal;
}
.all {
	display: block;
	height: 40px;
	color: #22b0ff;
	border: 1px solid #22b0ff;
	text-align: center;
	line-height: 40px;
	font-size: 16px;
}
.all:hover {
	background-color: #22b0ff;
	color: #fff;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值