Attribute Selectors





13
Date Submitted Wed. Nov. 9th, 2005 8:27 PM
Revision 1 of 1
Beginner vinnie
Tags Attribute | CSS
Comments 1 comments
Attribute Selectors
/*choose an element based on
whether it has an attribute.
in this case, we'll choose any
images with title attributes*/

img[title] {
  border: 5px solid red;
}

/*choose an element based on
the value of the attribute.
Let's go for all submit buttons
on forms*/

input[type="submit"] {
  color: white;
  background: blue;
}

/*choose an element based on
what the attribute value starts
with. In this example, grab
any links that start with "http://"
(usually links external to a site)*/

a[href|="http://"] {
  color: red;
  font-weight: bold;
}

/*choose an element based on a
substring of the attrbute's value.
In this one, let's go for links with
the substring ".com" in them*/

a[href~=".com"] {
  color: green;
}

Comments

Comments Internet Explorer Woes
Wed. Oct. 4th, 2006 9:40 PM    Helper Thomas

Voting