Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • Toggle search form

CSS Attribute Selectors

Posted on March 15, 2023March 15, 2023 By shani No Comments on CSS Attribute Selectors

CSS Attribute Selectors are a type of CSS selector that allows you to target elements based on the presence or value of their attributes. They are very useful when you need to target specific elements based on their attributes.

Here are some examples of CSS Attribute Selectors:

  1. [attribute] – selects all elements that have the specified attribute
a[target="_blank"] {
  color: red;
}

In this example, all a elements that have a target attribute with the value of _blank will have red text color.

  1. [attribute=value] – selects all elements that have the specified attribute with a specific value
input[type="text"] {
  border: 1px solid black;
}

In this example, all input elements that have a type attribute with the value of text will have a black border.

  1. [attribute^=value] – selects all elements that have the specified attribute with a value that begins with the specified value
a[href^="https"] {
  color: green;
}

In this example, all a elements that have an href attribute with a value that begins with https will have green text color.

  1. [attribute$=value] – selects all elements that have the specified attribute with a value that ends with the specified value
a[href$=".pdf"] {
  font-weight: bold;
}

In this example, all a elements that have an href attribute with a value that ends with .pdf will have bold font weight.

  1. [attribute*=value] – selects all elements that have the specified attribute with a value that contains the specified value
input[name*=user] {
  background-color: yellow;
}

In this example, all input elements that have a name attribute with a value that contains user will have a yellow background color.

These are just a few examples of how you can use CSS Attribute Selectors. They are very powerful and can help you target specific elements on your page based on their attributes.

CSS

Post navigation

Previous Post: CSS Image Sprites
Next Post: CSS Forms

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CSS Tutorial

  • Basic CSS Tutorial For Beginners
  • CSS Introduction
  • CSS Syntax
  • CSS Selectors
  • How To Add CSS
  • CSS Comments
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Margins
  • CSS Margin Collapse
  • CSS Padding
  • CSS Height, Width and Max-width
  • CSS Box Model
  • CSS Outline
  • CSS Text
  • CSS Fonts
  • CSS Web Safe Fonts
  • CSS Font Fallbacks
  • CSS Font Style
  • CSS Font Size
  • CSS Google Fonts
  • CSS Great Font Pairings
  • CSS Icons
  • CSS Links
  • CSS Lists
  • CSS Tables
  • CSS Layout – display: inline-block
  • CSS Layout – float and clear
  • CSS Layout – Horizontal & Vertical Align
  • CSS Layout – Overflow
  • CSS Layout – The display Property
  • CSS Layout – The z-index Property
  • CSS Layout – width and max-width
  • CSS Layout – The position Property
  • CSS Attribute Selectors
  • CSS Image Sprites
  • CSS Image Gallery
  • CSS Dropdowns
  • CSS Horizontal Navigation Bar
  • CSS Vertical Navigation Bar
  • CSS Navigation Bar
  • CSS Opacity / Transparency
  • CSS Pseudo-elements
  • CSS Pseudo-classes
  • CSS Combinators
  • CSS Math Functions
  • CSS The !important Rule
  • CSS Specificity
  • CSS Units
  • CSS Website Layout
  • CSS Counters
  • CSS Forms
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme