CSS3 adds attribute selectors: [attribute * = value], [attribute ^ = value], [attribute $ = value], and css3attribute

Source: Internet
Author: User

CSS3 adds attribute selectors: [attribute * = value], [attribute ^ = value], [attribute $ = value], and css3attribute

In CSS3, the [attribute * = value], [attribute ^ = value], and [attribute $ = value] selectors are added, so that the attribute selectors have the concept of wildcards.

The following is a complete sample code that uses these three attributes and the displayed page after running:

<! DOCTYPE html> 

Display the Running Effect in the browser:

The following example describes the CSS3 attribute selector.

1. [attribute * = value] attribute Selector

[Attribute * = value] The meaning of the attribute selector is to select the HTML element containing the value string in the attribute.

In the preceding example, [id * = irs], attribute is id, and value is irs. In this way, you must select the element containing the "irs" string in the id attribute, that is, the first div element, set the background color of the element to red.

2. [attribute ^ = value] attribute Selector

[Attribute ^ = value] attribute selector means to select an HTML element starting with a value string in the attribute.

In the preceding example, [id ^ = sec], attribute is id, and value is sec. In this way, you must select the element starting with the "sec" string in the id attribute, that is, the second div element, set the background color of the element to blue.

3. [attribute $ = value] attribute Selector

[Attribute $ = value] attribute selector means to select an HTML element ending with a value string in attribute.

In the above example, [id $ = ird], attribute is id, and value is ird. In this way, you must select the element ending with the "ird" string in the id attribute, that is, the third div element, set the background color of the element to green.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.