enabled
CSS :enabled Pseudo Class
The CSS :enabled pseudo-class selects and styles elements that are enabled.
These elements are usually form elements, such as buttons (<button>), select menus (<select>), input types (<input>), and textareas (<textarea>).
Enabled elements accept clicks, text input, or focus. (启用的元素接受点击、文本输入或焦点。)
Version
Version (版本)
HTML Living Standard (生活水平)
HTML5
Selectors Level 4 (选择器级别4)
Syntax
Syntax (语法)
:enabled {
css declarations;
}
Example of the :enabled selector:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
input {
border: 1px solid #ccc;
margin-bottom: 10px;
padding: 2px 5px;
}
input[type=text]:enabled {
background: #eee;
}
input[type=text]:disabled {
background: #ccc;
}
</style>
</head>
<body>
<h2>:enabled selector example</h2>
<form action="#">
<label for="name">First name:</label>
<input type="text" value="John" id="name">
<br>
<label for="lastname">Last name:</label>
<input type="text" value="Smith" id="lastname">
<br>
<label for="country">Country:</label>
<input type="text" disabled="disabled" value="10 High Street" id="country">
</form>
</body>
</html>
Example of the :enabled selector with the <option> tag:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
option:enabled {
background: #666;
}
</style>
</head>
<body>
<h2>:enabled selector example</h2>
<select>
<option value="paris">Paris</option>
<option value="london" disabled>London</option>
<option value="moscow">Moscow</option>
<option value="rome" disabled>Rome</option>
<option value="berlin">Berlin</option>
</select>
</body>
</html>