CSS选择符-----属性选择符

时间:2021-09-23 02:35:21

   Element[att]

选择具有att属性的E元素

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
input[name]{
border:1px solid red;
}
</style>
</head>
<body>
<div>
<span>用户名:</span> <input name="userName" value="userName"/><br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;密码:</span> <input value="userPwd"/>
</div>
</body>
</html>

   Element[att="val"]

        选择具有att属性且属性值等于val的E元素

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
input[name="userName"]{
border:1px solid red;
}
input[name="userPwd"]{
border:1px solid #0000FF;
}
</style>
</head>
<body>
<div>
<span>用户名:</span> <input name="userName" value="userName"/><br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;密码:</span> <input name="userPwd" value="userPwd"/>
</div>
</body>
</html>