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>
相关推荐
奇舞精选24 分钟前
你可能不知道但非常实用的 HTML5 元素
css
_揽29 分钟前
html如何在一张图片上的某一个区域做到点击事件
前端·html
踢足球的,程序猿32 分钟前
从 Vue 2.0 进阶到 Vue 3.0 的核心技术解析指南
前端·javascript·vue.js·前端框架·html
冷凌爱34 分钟前
Fetch与Axios:区别、联系、优缺点及使用差异
前端·node.js·js
袁煦丞1 小时前
跨平台终端王者Tabby:cpolar内网穿透实验室第632个成功挑战
前端·程序员·远程工作
Sailing1 小时前
Grafana-mcp-analyzer:基于 MCP 的轻量 AI 分析监控图表的运维神器!
前端·node.js·mcp
阿山同学.1 小时前
AWS 亚马逊 S3存储桶直传 前端demo 复制即可使用
前端·javascript·aws
Jolyne_1 小时前
grid 实现完美的水平铺满、间隔一致的自适应布局
前端·css
西洼工作室1 小时前
【解决导航栏字体图标渲染导致文本闪烁问题】采用腾讯视频的解决方案
前端·css·css3
WindrunnerMax2 小时前
从零实现富文本编辑器#5-编辑器选区模型的状态结构表达
前端·架构·github