Get the App
SLTechnology News&Howtos  ›  Development  › 

How attribute selectors are linked together in css

Shulou Source: shulou.com Published: 2022-06-01 10:47:45 10月03日 Update

Editor to share with you how to link the attribute selector in css, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

You can apply styles only to anchors (an elements) that have a href attribute:

A [href] {color:red;} example 3

You can also make selections based on multiple attributes by linking the property selectors together.

For example, to set the text of a HTML hyperlink with both href and title attributes to red, you can write:

A [href] [title] {color:red;} example 4

You can use this feature in some creative ways.

For example, you can apply styles to all images with the alt attribute to highlight these valid images:

Img [alt] {border: 5px solid red;}

Tip: the above special case is more suitable for diagnosis than design, that is, to determine whether the image is really valid.

Example 5: using a property selector for an XML document

Attribute selectors are useful in XML documents because the XML language advocates specifying element and attribute names for the purpose of elements and attributes.

Suppose we design a XML document to describe the planets in the solar system. If we want to select all the planet elements with the moons attribute and display them in red so that we can pay more attention to the planets with moons, we can write:

Planet [moons] {color:red;}

This causes the text of the second and third elements in the following tag snippet to appear in red, but the text of the first element is not red:

VenusEarthMars above is all the content of this article entitled "how attribute selectors are linked together in css". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Attributes selections elements links red examples images text documents articles valid content styles planets applications design three not much creative just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Huawei MySQL Redmi