CSS中常用的伪元素选择器

伪元素,表示页面中一些特殊的并不真实存在的元素(元素的位置)

1,::first-letter 表示第一个字母

2,::first-line 表示第一行

3,::selection 选中的内容

4,::before 元素的开始位置

5,::after 元素的结束位置

before和after必须要结合content使用

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* lorem  生成随机英文段落
        下载Chinese Lorem插件,jw 生成随机中文段落 */
 
      /* 需求一:让文章的首字母一直为字体为24px */
      p::first-letter {
          font-size: 24px;
      }
      /* 需求二:让文章的第一行添加背景色黄色 */
      /* 需求三:让选中的内容,字体为红色 */
      /* 需求四:在元素开始的位置前+'abc' */
      p::before{
          content: '你好';
          color:red
      }
 
    </style>
  </head>
  <body>
      <q>hello</q>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro fugiat maiores sit ex expedita beatae, sint quisquam amet quod cupiditate, tempora omnis impedit deleniti, iure fuga illo
      quibusdam. Alias, soluta?
    </p>
  </body>
</html>
相关推荐
PedroQue991 小时前
Vite插件v0.2.6:架构优化与自动化升级
前端·vite
threerocks2 小时前
什么?我连 A2A、MCP 都没学会,现在又来了 AG-UI、A2UI.
前端·aigc·ai编程
牛奶3 小时前
如何自己写一个浏览器插件?
前端·chrome·浏览器
亿元程序员3 小时前
为什么Cocos都4.0了还有人用2.x?
前端
MomentYY4 小时前
AI 到底是“懂”,还是在“猜”?
前端·人工智能·ai编程
鹏毓网络科技4 小时前
Cursor Rules 文件配置实战:3 个隐藏参数让我每月少写 40% 样板代码
前端·github
没烦恼3014 小时前
无痕模式下 HTTP\-First 拦截引发的“页面刷新”误判
前端
文心快码BaiduComate4 小时前
从个人提效到组织提效:Comate辅助构建自我进化的AI研发系统
前端·程序员
hunterandroid4 小时前
Compose 状态管理:remember、rememberSaveable 与状态提升
前端
星栈5 小时前
Dioxus 接数据库最容易写歪的 3 个地方:sqlx + SQLite 怎么接才顺
前端·rust·前端框架