background-color: yellow;
}
For example, select all elements with the [target] attribute and style the element.
Links with target properties will have a yellow background:
quantrimang.com
meta.vn
gamevui.vn
Note: To [attribute] can work in IE8 and earlier, it is necessary to declare the element at the beginning of the document.
The [attribute = "value"] selection is used to select all elements with the [attribute] attribute and the value specified.
a[target="_blank"] {
background-color: yellow;
}
For example, select all elements with the target = "_ blank" attribute :
Links with target = "_ blank" attribute will have a yellow background:
quantrimang.com
meta.vn
gamevui.vn
Note: For [attribute = "value"] to work in IE8 and earlier, it is necessary to declare the element at the beginning of the document.
[Attribute ~ = "value"] selector is used to select all elements with the [attribute] attribute containing the specified value value .
[title~="flower"] {
border: 5px solid purple;
}
For example, select all elements whose title attribute contains the word "flower":
Note : The selector will only select elements whose title attribute contains values such as title = "flower", title = "summer flower" or title = "flower new" , without selecting the elements of the title = "my -flower " or title =" flowers ".
The selector [attribute | = "value"] is used to select all elements with the [attribute] attribute starting with the value specified.
[class|="top"] {
background: purple;
}
For example, select all elements with class attributes starting with the word "top":
CSS and CSS3
Note : The selector will select only elements with class attributes starting with a single word, or a single word and a word in the top- form , such as top-header, top-text, not selecting those element with other words like topcontent.
The [attribute ^ = "value"] selector is used to select all elements with the [attribute] attribute starting with the specified value value , different from [attribute | = "value"] above where it has no exception and selects all elements that begin with value, including words in the form adjacent to another word.
[class^="top"] {
background: purple;
}
For example, select all elements with class attributes starting with the word "top":
CSS and CSS3
Note: For [attribute ^ = "value"] to work in versions from IE8 and earlier, it is necessary to declare the element at the beginning of the document.
[Attribute $ = "value"] selector is used to select all elements with the [attribute] attribute ending with the specified value value .
[class$="test"] {
background: yellow;
}
Note : Value is not necessarily a word!
For example, select all elements with class properties ending with the word "test":
Stay up to date with the latest trends, discoveries, and research
science and technology
[Attribute * = "value"] selector is used to select all elements with the [attribute] attribute contained by the specified value value .
[class*="te"] {
background: yellow;
}
Note : Value is not necessarily a word!
For example, select all elements with class attributes that contain the word "te":
Stay up to date with the latest trends, discoveries, and research
science and technology
Previous article: Image Sprite in CSS
Next lesson: Form - Form in CSS