css3 - 属性选择器

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>
        /* 【1】选择具有某个属性的元素*/
        /*选中具有value属性的input标签 */
        input[value] {
            color: red;
        }

        a[title] {
            color: green;
        }

        /* 【2】选择具有某个属性且值为xx的元素 */
        input[type=button] {
            background-color: pink;
        }

        /* 【3】选择具有某个属性且值是以xx开头的元素 */
        div[class^=box] {
            color: blue;
        }

        /* 【4】选择具有某个属性且值是以xx结尾的元素 */
        p[class$=-hd] {
            color: red;
        }

        /* 【5】选择具有某个属性且值包含xx的元素 */
        section[class*=icon] {
            color: pink;
        }
    </style>
</head>

<body>
    <!-- 属性选择器:根据标签的属性,来选中元素。 -->
    <input type="text">
    <input type="text" value="">
    <hr>
    <a href="#">测试</a>
    <a href="#" title="百度一下">百度</a>
    <hr>
    <input type="submit">
    <input type="button">
    <hr>
    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>
    <div class="abc">4</div>
    <hr>
    <p class="box-hd">我是p1</p>
    <p class="bd">我是p2</p>
    <p class="hezi-hd">我是p3</p>
    <hr>
    <section class="icon01">s1</section>
    <section class="box-icon">s2</section>
    <section class="aliamma-icon-box">s3</section>
</body>
</html>
相关推荐
程序员爱钓鱼2 分钟前
Go语言实战案例 — 项目实战篇:简易博客系统(支持评论)
前端·后端·go
excel7 小时前
ES6 中函数的双重调用方式:fn() 与 fn\...``
前端
可乐爱宅着7 小时前
全栈框架next.js入手指南
前端·next.js
你的人类朋友9 小时前
什么是API签名?
前端·后端·安全
会豪11 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子11 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶11 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子11 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_11 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_233311 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts