0
点赞
收藏
分享

微信扫一扫

Java项目:基于SSM框架实现的智慧城市实验室管理系统分前后台【ssm+B/S架构+源码+数据库+毕业论文】

其生 2024-07-24 阅读 8
css前端

目录

所有选择器

选择器用法
id选择器#myid
类选择器.myclassname
标签选择器div,h1,p
相邻选择器h1+p
子选择器ul > li
后代选择器li a
通配符选择器*
属性选择器a[rel=“external”]
伪类选择器a:hover, li:nth-child

伪类选择器

定义:结构伪类选择器主要根据的是文档的结构来选择元素,常常用在根据父级选择器选出某些想要的子元素。

主要语法如下:

编号语法含义
1E:first-child匹配父元素中的第一个子元素E
2E:last-child匹配父元素中最后一个E元素
3E:nth-child(n)匹配父元素中的第n个子元素E
4E:first-of-type指定类型E的第一个
5E:last-of-type指定类型E的最后一个
6E:nth-of-type(n)指定类型E的第n个

区别(:nth-child(n) 和 :nth-of-type(n))

示例:

<div id="parent">
  <p>Paragraph 1</p>
  <div>Div 1</div>
  <p>Paragraph 2</p>
  <div>Div 2</div>
  <p>Paragraph 3</p>
</div>
/* 使用 :nth-child(n) */
#parent > *:nth-child(2) {
  color: red;
}

/* 使用 :nth-of-type(n) */
#parent > p:nth-of-type(2) {
  color: blue;
}
举报

相关推荐

0 条评论