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>
相关推荐
IT_陈寒1 小时前
Redis误用keys命令把生产环境搞崩了,血的教训
前端·人工智能·后端
计算机魔术师2 小时前
5000亿估值冲刺科创板,DeepSeek 为何急着上市?
前端
我血条子呢2 小时前
前端解析word方案
前端·word
kyriewen2 小时前
我用 AI 写完一个需求后才发现,最难的不是 prompt,而是验收
前端·程序员·ai编程
申行2 小时前
Vue 3 + DYMO Connect Framework 实战:从标签模板到打印服务的完整实现
前端
两只羊ovo2 小时前
Vue 3 + DeepSeek 流式输出实战:从“干等”到“打字机”体验
前端·vue.js
Yeyu2 小时前
车载多 App 同屏渲染(二):SurfaceControlViewHost 跨进程
前端
樊小肆2 小时前
离谱,每轮请求 25% 的 token,竟在重发模型想完就扔的内心独白
前端·人工智能·agent
小妖现世2 小时前
前端面试复习笔记:React 高频题 + JS 手写题
前端
holidaypenguin2 小时前
Windows 本地 HTTPS 证书生成指南
前端