An article explaining the UI state pseudo-class selector in CSS in detail

青灯夜游
Release: 2022-08-03 12:09:49
Original
2409 people have browsed it

An article explaining the UI state pseudo-class selector in CSS in detail

UI state pseudo-class selector is used to select UI elements in a certain state. It is mainly used on HTML forms. It defines different styles according to the different states of the form elements. to enhance user experience.

Characteristics of the UI status pseudo-class selector: the specified style only works in a certain state

The status of the form element includes focus, loss of focus, selected, unselected, and available , unavailable, valid, invalid, required, optional, read-only, etc.

UI status pseudo-class selector
Selector Function description Version
E:focused Select the focused element in the form 3
E:checked Select the selected radio or checkbox element in the form 3
E:enabled Select the elements available in the form 3
E:disabled Select elements that are not available (i.e. disabled) in the form 3
E:valid Select elements whose content in the form meets the requirements 3
E:invalid Select elements where the content filled in the form does not meet the requirements, such as illegal URL or Email, or does not match the pattern given by the pattern attribute 3
E:in-range Select elements whose numbers entered in the form are within the valid range 3
E:out-of -range Select elements where the number entered in the form exceeds the valid range 3
E:required Select elements in the form Required elements 3
E:optional Select elements that are allowed to use the required attribute and are not specified as required in the form 3
E :read-only Select elements in the form that are read-only 3
E:read-write Select Elements in the form whose status is not read-only 3
E:default Select the radio button or checkbox that is in the selected state by default Select box, even if the user sets the selected state of the radio button or check box control to a non-selected state, the style specified in the E:default selector is still valid 3
E:indeterminate The style of the entire group of radio button boxes when none of the radio button boxes in the selector form is selected. If the user selects any of the radio button boxes box, the style is unassigned 3

1. E:hover selector

is used to specify the style used by the element when the mouse pointer moves over it

Usage:

<元素>:hover{ 
CSS样式 
}
Copy after login

We can add the type attribute of the element in "".

Example:




    


    这是一个链接
    这是另一个链接

Copy after login

The running result is as shown below:

An article explaining the UI state pseudo-class selector in CSS in detail

2. E:active selector

:active: Define the style when the link is clicked.

You can define the style when clicking a link through the :active pseudo-class selector. The sample code is as follows:




    


    这是一个链接
    这是另一个链接

Copy after login

The running result is as shown below:

An article explaining the UI state pseudo-class selector in CSS in detail

3. E:link selector

:link: Define ordinary or unvisited links style;

You can set the style for ordinary or unvisited links through the :link pseudo-class selector. The sample code is as follows:




    


    这是一个链接
    这是另一个链接

Copy after login

The running results are as shown below:

An article explaining the UI state pseudo-class selector in CSS in detail

4. E: visited selector

: visited: defines the visited link Style;

You can set the style for the visited link through the :visited pseudo-class selector. The sample code is as follows:




    


    这是一个链接
    这是另一个链接

Copy after login

The running result is as shown below:

An article explaining the UI state pseudo-class selector in CSS in detail

5. E: focus selector

: focus: Used Specify the style used by the element to obtain the cursor focus

The sample code is as follows:





选择器E:hover、E:active和E:focus



选择器E:hover、E:active和E:focus

姓名:

密码:
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail

6, E:enabled pseudo Class selector and E:disabled pseudo-class selector

1), E:enabled selector is used to specify the style when the element is in the available state.
2). The E:disabled selector is used to specify the style when the element is in a disabled state.





E:enabled伪类选择器与E:disabled伪类选择器



E:enabled伪类选择器与E:disabled伪类选择器

姓名:

学校:
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail

7. E:read-only pseudo-class selector and E:read-write pseudo-class selector

1), E:read-only selector is used to specify the style when the element is in the read-only state.
2). The E:read-write selector is used to specify the style when the element is in a non-read-only state.





read-only伪类选择器与E:read-write伪类选择器



read-only伪类选择器与E:read-write伪类选择器

姓名:

学校:
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail

8, pseudo-class selectors E:checked, E:default and indeterminate

1 ), E:cehcked pseudo-class selector is used to specify the style when the radio radio button or checkbox in the form is in the selected state.
2). The E:default selector is used to specify the style of the radio button or check box control that is in the selected state by default when the page is opened.
3). The E: indeterminate selector is used to specify the style of the entire group of radio button boxes when no single radio button box in a group of radio button boxes is set to the selected state when the page is opened.





checked伪类选择器



checked伪类选择器

房屋状态: 天然气 宽带
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail

Default selection





default伪类选择器



default伪类选择器

房屋状态: 天然气 宽带
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail





indeterminate伪类选择器



indeterminate伪类选择器

性别:
Copy after login

An article explaining the UI state pseudo-class selector in CSS in detail

9. Pseudo-class selector E::selection

The E:selection pseudo-class selector is used to specify the style when the element is selected.





伪类选择器E::selection



伪类选择器E::selection

Copy after login

1An article explaining the UI state pseudo-class selector in CSS in detail

10. E:invalid pseudo-class selector and E:valid pseudo-class selector

1), E:invalid pseudo-class selector is used to specify the style when the element content cannot pass the check specified by HTML5 by using attributes such as requirede of the element or the element content does not conform to the format specified by the element.
2). The E:valid pseudo-class selector is used to specify the style when the element content can pass the check specified by HTML5 using attributes such as requirede of the element or the element content conforms to the format specified by the element.





E:invalid伪类选择器与E:valid伪类选择器



E:invalid伪类选择器与E:valid伪类选择器

Copy after login

11. E:required pseudo-class selector and E:optional pseudo-class selector

1)、E:required伪类选择器用来指定允许使用required属性,而且已经指定了required属性的input元素、select元素以及textarea元素的样式。
2)、E:optional伪类选择器用来指定允许使用required属性,而且未指定了required属性的input元素、select元素以及textarea元素的样式。



	
		
		E:required伪类选择器与E:optional伪类选择器
		
	
	
		

E:required伪类选择器与E:optional伪类选择器

姓名:

学校:
Copy after login

12、E:in-range伪类选择器与E:out-of-range伪类选择器

1)、E:in-range伪类选择器用来指定当元素的有效值被限定在一段范围之内,且实际的输入值在该范围之内时的样式。
2)、E:out-of-range伪类选择器用来指定当元素的有效值被限定在一段范围之内,但实际输入值在超过时使用的样式。





E:in-range伪类选择器与E:out-of-range伪类选择器



E:in-range伪类选择器与E:out-of-range伪类选择器

Copy after login

1An article explaining the UI state pseudo-class selector in CSS in detail  

各UI元素状态伪类选择器受浏览器的支持情况

选择器 Firefox Safari Opera IE8 Chrome
E:hover
E:active x
E:focus
E:enable x
E:disable x
E:read-only x x x
E:read-write x x x
E:checked x
E:default x x x x
E:indeterminate x
E:selection x

(学习视频分享:web前端入门

The above is the detailed content of An article explaining the UI state pseudo-class selector in CSS in detail. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!