Detailed explanation of the use of CSS attribute selectors (css introductory tutorial)

(*-*)浩
Release: 2019-11-26 13:38:13
original
2874 people have browsed it

Detailed explanation of the use of CSS attribute selectors (css introductory tutorial)

Set styles for HTML elements with specified attributes. (Recommended learning: CSS Getting Started Tutorial)

You can set styles for HTML elements with specified attributes, not just class and id attributes.

Note: IE7 and IE8 only support attribute selectors when !DOCTYPE is specified. In IE6 and lower, attribute selection is not supported.

Attribute Selector

The following example sets the style for all elements with the title attribute:

[title]
{
color:red;
}
Copy after login

Attribute and value selector

The following example styles all elements with title="W3School":

[title=hello]
{
border:5px solid blue;
}
Copy after login

Attribute and value selectors - multiple values

The following example sets styles for all elements that contain a title attribute with a specified value. Applies to attribute values ​​separated by whitespace:

[title~=hello] { color:red; }
Copy after login

The following example styles all elements with a lang attribute that contains the specified value. Applies to attribute values ​​separated by hyphens:

[lang|=en] { color:red; }
Copy after login

Setting the style of the form

The attribute selector is special when styling the form without a class or id Useful:






Copy after login

The above is the detailed content of Detailed explanation of the use of CSS attribute selectors (css introductory tutorial). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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 [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!