子元素选择器
来源:互联网 发布:1api域名注册 编辑:程序博客网 时间:2024/06/03 18:04
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*
* 为第一个标签设置一个背景颜色为黄色
* :first-child 可以选中第一个子元素
* :last-child 可以选中最后一个子元素
*
* p:last-child{
* background-color: yellow;
* }
*
* :nth-child 可以选中任意位置的子元素
* 该选择器后面可以指定一个参数,指定要选则的第几个元素
* even 表示偶数位置的子元素
* odd 表示奇数位置的子元素
*/
p:nth-child(2){
background-color: pink;
}
/*
* :first-of-type
* :last-of-type
* :nth-of-type
* 和:first-child这些非常类似
* 只不过child是在所有子元素中排列
* 而type是在当前类型的子元素中排序
*/
p:nth-of-type(4){
background-color: skyblue;
}
/*
* 否定伪类:
* 作用:可以从已选的元素中剔除某些元素
* 语法:
* :not(选择器)
*/
p:not(.a){
background-color:yellow;
}
</style>
</head>
<body>
<span>qwqwwqw</span>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p class="a">我是一个段落</p>
<p class="a">我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*
* 为第一个标签设置一个背景颜色为黄色
* :first-child 可以选中第一个子元素
* :last-child 可以选中最后一个子元素
*
* p:last-child{
* background-color: yellow;
* }
*
* :nth-child 可以选中任意位置的子元素
* 该选择器后面可以指定一个参数,指定要选则的第几个元素
* even 表示偶数位置的子元素
* odd 表示奇数位置的子元素
*/
p:nth-child(2){
background-color: pink;
}
/*
* :first-of-type
* :last-of-type
* :nth-of-type
* 和:first-child这些非常类似
* 只不过child是在所有子元素中排列
* 而type是在当前类型的子元素中排序
*/
p:nth-of-type(4){
background-color: skyblue;
}
/*
* 否定伪类:
* 作用:可以从已选的元素中剔除某些元素
* 语法:
* :not(选择器)
*/
p:not(.a){
background-color:yellow;
}
</style>
</head>
<body>
<span>qwqwwqw</span>
<p>我是一个段落</p>
<p>我是一个段落</p>
<p class="a">我是一个段落</p>
<p class="a">我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>
</body>
</html>
阅读全文
0 0
- 子元素过滤选择器
- CSS 子元素选择器
- CSS 子元素选择器
- CSS 子元素选择器
- 选择器 子元素
- 子元素过滤选择器
- 子元素过滤选择器
- 子元素过滤选择器
- 关于子元素选择器
- 子元素选择器
- 子元素过滤选择器
- 0418-子元素选择器
- 子元素选择器
- html 子元素选择器
- CSS 子元素选择器
- CSS 子元素选择器
- 子元素选择器、属性选择器、表单选择器
- 通配符选择器子元素选择器后代选择器
- 最大权闭合子图(poj 2987 Firing)
- 关于动态代理的一点疑问
- 教学有法、学不可已 — 在线学习的十个好处
- ubuntu ssh 免密码登录
- HDU58739(Football Games) 大连网络赛
- 子元素选择器
- 位操作基础篇之位操作全面总结
- 数据结构与算法系列 目录
- 兄弟元素选择器
- 2017.08.28工作日记
- 第一章 Shiro简介——《跟我学Shiro》
- POJ2104:划分树求区间第k小
- 主席树,开坑POJ2104,EOJ3335&hdu6162,hdu5919
- 数据库-mysql-linux下常用命令