:focus
伪类选择器用于选取获取焦点的表单元素。
一般情况,<input>
类表单元素才能获取光标,因此这个选择器注意针对表单元素来说的。
示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer" />
<title>验证</title>
<style>
/* 选取获取光标的input表单元素 */
input:focus {
background-color: yellow;
}
</style>
</head>
<body>
<input type="text">
<input type="text">
<input type="text">
</body>
</html>
效果: