:focus 选择器用于选取获得焦点的元素。
提示:接收键盘事件或其他用户输入的元素都允许 :focus 选择器。
注释:如果 :focus 用于 IE8 ,则必须声明 <!DOCTYPE>。
选择获得焦点的输入字段,并设置其样式:
<!DOCTYPE html>
<html>
<head>
<style>
input:focus
{
background-color:yellow;
}
</style>
</head>
<body>
<p>在文本框中点击,您会看到黄色的背景:</p>
<form>
First name: <input type="text" name="firstname" /><br>
Last name: <input type="text" name="lastname" />
</form>
<p><b>注释:</b>如果 :focus 用于 IE8 ,则必须声明 <!DOCTYPE>。</p>
</body>
</html>
支持:不支持
<view>
姓名:<input type='text' ></input>
地区: <input type='text' ></input>
</view>
view{
margin: 10px;
padding: 5px;
}
input:focus{
background-color: yellow;
}