Selecting elements by attributes
You can select elements by attributes inside square brackets [].
a[target] {} /* selecting links that have the "target" parameter */
a[target][title] {} /* a selection of links that have two parameters: target and title */
Selecting elements without a specified attribute
You can also select elements without the specified attribute using the :not() pseudo-class.
img:not([alt]) {} /* Selecting images without an "alt" attribute */
The example above shows a selection of images without an alt attribute.
According to the HTML standard, each image must have an alt attribute (may be empty).
Selecting elements with specified parameters in attributes
You can select elements with the specified parameters:
a[target="_blunk"] /* a selection of links with the target parameter equal to "_blunk" */
a[href*="mysite"] /* a selection of links where the text "mysite" appears in the URL */
a[href^="http"] /* a selection of links whose URL begins with "http" */
a[href$=".webp"] /* a selection of links whose URL ends with ".webp" */
Below is an example of a selection of links to external sites..
a[href^="http:"],
a[href^="https:"] { /* code */ }
Поддержать автора
Все статьи создаются и поддерживаются одним человеком,
если вам нравится контент, вы можете поддержать автора сайта
