当前位置: 首页 > news >正文

css-伪类选择器

css记录

  • 选择器
    • 伪类选择器
      • :is、:where
      • :has

选择器

伪类选择器

:is、:where

栗子完整代码

<template><section class="is-styling"><p>我是is的section</p></section>![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/b0d3967ff5c147ba91c6680f1d93250b.png)<aside class="is-styling"><p>我是is的aside</p></aside><footer class="is-styling"><p>我是is的footer</p></footer><br /><section class="where-styling"><p>我是where的section</p></section><aside class="where-styling"><p>我是where的aside</p></aside><footer class="where-styling"><p>我是where的footer</p></footer>
</template><script setup></script><style lang="scss" scoped>
:is(section.is-styling, aside.is-styling, footer.is-styling) p {color: red;
}:where(section.where-styling, aside.where-styling, footer.where-styling) p {color: green;
}
</style>

栗子实现的效果-:is和:where后跟选择器列表时-作用一样:

在这里插入图片描述

:where后跟条件的栗子完整代码

<template><section class="is-styling"><p>我是is的section</p></section><aside class="is-styling"><p>我是is的aside</p></aside><footer class="is-styling"><p>我是is的footer</p></footer><br /><section class="where-styling"><p>我是where的section</p></section><aside class="where-styling"><p>我是where的aside</p></aside><footer class="where-styling"><p>我是where的footer</p></footer></template><script setup></script><style lang="scss" scoped>
section:where([class^="where"]) {font-weight: bold;
}
</style>

上面栗子实现的效果:
在这里插入图片描述

相同点: :is、:where选择器都是根据条件来定位元素。
不同点: :is()用于根据选择器列表匹配元素,保持原有选择器的特定性。而:where()不仅可以根据选择器列表匹配元素,而且可根据条件匹配元素。同时降低选择器的优先级,避免因选择器过长而导致的优先级问题

:has

可以用于**基于后代元素**来定位元素,根据元素内部是否存在特定的子元素来选择该元素。

栗子完整代码

<template><section class="is-styling"><p>我是is的section</p></section><aside class="is-styling"><p>我是is的aside</p></aside><footer class="is-styling"><p>我是is的footer</p></footer><br /><section class="where-styling"><p>我是where的section</p><span>我是span元素</span></section><aside class="where-styling"><p>我是where的aside</p></aside><footer class="where-styling"><p>我是where的footer</p></footer></template><script setup></script><style lang="scss" scoped>
section:has(span) {background: orange;
}
</style>

栗子实现的效果:
在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • SpringBoot使用泛型出入参+策略模式+反射+缓存实现统一POST接口入口
  • 连锁企业组网的优化解决方案
  • 通过Java实现插入排序(直接插入,希尔)与选择排序(直接选择,堆排)
  • 12. 计算机网络TCP四次挥手
  • 【avue+vue2+elementui】删除、rules、页面跳转和其他问题
  • 探索编程世界:大学新生入门指南
  • uniapp小程序中富文本内容渲染图片不展示的问题
  • 大模型的一些思考
  • MATLAB(10)分类算法
  • json-server(快速搭建本地 RESTful API 的工具)
  • 集群、分布式和微服务
  • Java SpringTask定时自动化处理
  • 装修新选择:探索浦东地区口碑排名前五的大平层装修公司!
  • 本地node搭建web服务器
  • Redis 典型应用-缓存
  • [iOS]Core Data浅析一 -- 启用Core Data
  • ES6--对象的扩展
  • Golang-长连接-状态推送
  • js 实现textarea输入字数提示
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • MySQL的数据类型
  • SQLServer之创建显式事务
  • 工程优化暨babel升级小记
  • 关于List、List?、ListObject的区别
  • 关于使用markdown的方法(引自CSDN教程)
  • 区块链技术特点之去中心化特性
  • 如何选择开源的机器学习框架?
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 详解移动APP与web APP的区别
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 原生Ajax
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • #Linux(权限管理)
  • #QT(串口助手-界面)
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • %check_box% in rails :coditions={:has_many , :through}
  • (八)Flask之app.route装饰器函数的参数
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (南京观海微电子)——I3C协议介绍
  • (全注解开发)学习Spring-MVC的第三天
  • (顺序)容器的好伴侣 --- 容器适配器
  • (一)spring cloud微服务分布式云架构 - Spring Cloud简介
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (转)Oracle存储过程编写经验和优化措施
  • (转)setTimeout 和 setInterval 的区别
  • (转)我也是一只IT小小鸟
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .net 调用php,php 调用.net com组件 --
  • .NET 直连SAP HANA数据库
  • .net解析传过来的xml_DOM4J解析XML文件
  • .NET开源、简单、实用的数据库文档生成工具
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • .NET开源项目介绍及资源推荐:数据持久层 (微软MVP写作)
  • // an array of int