---
title: "CSS选择器基础笔记"
author: "PatrickZhong"
date: "2011-09-26T12:31:28Z"
tags: []
categories: ["Web前端"]
slug: "css"
draft: false
lastmod: "2011-09-26T12:32:58Z"
id: 1180517
url: "https://patrickzhong.iteye.com/blog/1180517"
---

CSS selectors

```html

1)[attribute] base on Attribute
a[href] { text-decoration: none; }

2)[attribute=val] base on the Value of an attribute
a[href=www.iteye.com]{ text-decoration: none; }

3)[attribute~=val] contain the space-separated attribute somewhere in the value
a[title~=tv hd digital] { text-decoration: none; }
/* if title's value contains the word 'tv' or 'hd' or 'digital', then apply the CSS */

4)[attribute|=val] contain the attribute with a hyphen, must start with the value
a[title|=apple] { color: red; }
/* <a title="apple-banana">link</a> */

CSS3
1)[attribute^=val] attribute’s value begins with val
a[href^=mailto:] { color: red; }

2)[attribute$=val] attribute’s value ends with val
a[href$='.rss'] { color: red; }

3)[attribute*=val] attribute value is anywhere within val
a[href *=username] { color: red; }

```