Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 17, 2021 04:24 pm GMT

CSS Attribute Selectors

CSS Attribute SelectorsCSS Attribute Selectors. An attribute selector in CSS is utilized to pick any HTML elements with some particular attribute value or attribute. This is an excellent technique to style any HTML elements by making an attribute selector arrange them based on some single attributes and the single attribute selectors which is selecting those elements with the same attribute values or attributes. In our last article we discussed about Types of CSS Selectors

Example: As we know that styles the HTML tags with their tag names, ID names, class names, etc. These will apply the settings to the complete tag or complete class or complete id names within the page.

How does Attribute Selector work in CSS?

CSS attribute selector is operating based on attribute preference given to a specific selector.

CSS Attribute Selectors

1.[attribute] Selector
2.[attribute~="value"] Selector
3.[attribute="value"] Selector
4.[Attribute$= value] selector
5.[attribute*="value"] Selector

[attribute] Selector

This is used to pick an HTML tag with the wanted attribute only.

<a href="#">Home</a><a href="#" target="">Services</a><style>a[target] { /*This will color the a tag with target attribute*/color: blue;}</style>

[attribute~="value"] Selector

This is used to pick HTML elements with wanted attribute value holds a given word anyplace in the selector.

<style>[class~=soft] {color: hotpink;border: 2px solid #eee;font-size: 18px;}</style><p class="soft">Attribute ~ Selector:  This is utilized to select HTML elements with needed attribute and value.</p>

[attribute="value"] Selector

<style>p[class="psoft {color: hotpink;border: 2px solid #eee;font-size: 18px;}</style><p class="soft">Attribute Value Selector:  This is used to select HTML elements with needed  attribute and value.</p>

[Attribute$= value] selector

<style>[class$="soft"] {color: hotpink;border: 2px solid #eee;font-size: 18px;}</style><p class="soft"> Attribute $ Selector: This is used to select HTML tags whose attribute value ends with particular value.</p>

[attribute*="value"] Selector

<style>[class*="soft"] {color: hotpink;border: 2px solid #eee;font-size: 18px;}</style><p class="soft"> Attribute * Selector:  This is used to select HTML elements whose attribute value starting with specified value anywhere in the attribute.</p>

I shared this post from CSS Attribute Selectors you can read in detail from there.

If you have any question please help to improve. Thank you.


Original Link: https://dev.to/elinabey/css-attribute-selectors-422j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To