代码示例:(标识:css_form_focus_1)
<!DOCTYPE html>
<html>
<head>
<style> 
input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
  border: 1px solid #555;
  outline: none;
}

input[type=text]:focus {
  background-color: lightblue;
}
</style>
</head>
<body>

<p>在本例中,我们使用了 :focus 选择器,在文本字段获得焦点时(被点击)为其添加背景色:</p>

<form>
  <label for="fname">First Name</label>
  <input type="text" id="fname" name="fname" value="Bill">
  <label for="lname">Last Name</label>
  <input type="text" id="lname" name="lname" value="Gates">
</form>

</body>
</html>
运行结果: