Attribute Selector - Attribute Selector in CSS
What is an attribute selector?
Attribute selector is the way to select elements you want to style (style) in HTML documents based on the attributes of one or more HTML tags.
Attribute selector can select objects without having to declare additional Classes or IDs into HTML tags and still be able to navigate to those components, making the code more neat and coherent.
Some Attribute selector stand out
This article TipsMake.com would like to introduce some outstanding Attribute selector sets that are most commonly used:
- [attribute]
- [attribute = "value"]
- [attribute ~ = "value"]
- [attribute | = "value"]
- [attribute ^ = "value"]
- [attribute $ = "value"]
- [attribute * = "value"]
[Attribute] selector
[Attribute] selector is used to select all elements with the specified [attribute] attribute.
a[target] {
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.
[Attribute = "value"] selector
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]
[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":
All images with the title attribute contain the word "flower", then the border is added
purple.
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 ".
Picker [attribute | = "value"]
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":
Website Administration Network
Technology - Programming
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.
Selection [attribute ^ = "value"]
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":
Website Administration Network
Technology - Programming
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.
Picker [attribute $ = "value"]
[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]
[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
You should read it
May be interested
- Instructions on how to make hidden folders in USB when infectedthe following article will guide you how to make hidden folders in usb or any folder.
- Class properties in HTMLin html, class properties are used to identify one or more class names for html elements.
- What is ABAC? Advantages and disadvantages of Attribute-Based Access Controlabac (attribute-based access control) is a method of controlling access based on attributes of users, resources and environments.
- Attributes in jQuerysome of the most basic components, we can manipulate dom elements, are properties and attributes assigned to those elements.
- Attributes in HTMLproperties are used to add information to elements in html.
- How to Remove 'Read Only' Attribute on MS Word Filesthis article shows you how to remove 'read only' mode, which does not allow editing on microsoft word documents. although you cannot remove the read-only mode of a secured word document without knowing the password, you can easily copy the word document content into a new word file.
- SEQUENCE in SQL Serversequence is often used in databases because it is necessary for many applications. the article will provide syntax and examples of how to create and delete the sequence and its attributes in sql server.
- HTML color code - color code table in htmlthe color displayed is a combination of 3 colors red, green and blue. below is a table of color codes in html and how to use color codes in html
- The vars () function in Pythonthe vars () function in python returns the __dict__ attribute of the passed object if the object has the __dict__ attribute.
- Things to know about the :nth-child() selector in CSS:nth-child() in css is especially useful in styling complex tables and lists. here's what you need to know about :nth-child() in css.