属性选择器,字面意思就是根据标签中的属性,选中当前的标签。

属性选择器 通常在表单控件中 使用比较多

 

 

根据属性查找

/*用于选取带有指定属性的元素。*/
<!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">
    <title>Title</title>
    <style type="text/css">
        label[for]{
            color: red;
        }
    </style>

</head>
<body>
    <div>
        <form>
            <div>
                <label for="user">用户名</label>
                <input type="text" id="user">
            </div>

        </form>
    </div>
</body>
</html>

 

前端 CSS的选择器 属性选择器

根据属性和值查找

/*用于选取带有指定属性和值的元素。*/
<!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">
    <title>Title</title>
    <style type="text/css">
        label[for="user"]{
            color: red;
        }
    </style>

</head>
<body>
    <div>
        <form>
            <div>
                <label for="user">用户名</label>
                <input type="text" id="user">
            </div>

        </form>
    </div>
</body>
</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">
    <title>Title</title>
    <style type="text/css">
        input[type="text"]{
            color: red;
        }
    </style>

</head>
<body>
    <div>
        <form>
            <div>
                <label for="user">用户名</label>
                <input type="text" id="user">
            </div>

        </form>
    </div>
</body>
</html>

前端 CSS的选择器 属性选择器

 

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2021-10-26
  • 2021-11-12
  • 2021-06-12
  • 2022-01-28
  • 2021-09-14
  • 2021-10-06
猜你喜欢
  • 2021-12-15
  • 2022-01-20
  • 2021-04-27
  • 2021-07-23
  • 2021-04-22
相关资源
相似解决方案