Tuesday, March 2, 2010

CSS Selectors: Cheat Sheet

'Class' selectors

.headline - select every element that has the 'headline' class.

'Tag' selectors

p - select every paragraph on the page.
a - select every link/anchor on the page.
h1 - select every Heading 1 tag on the page.

'Id' selectors

#item-price - select the element that has the 'id' "item-price".

'Nth element' selectors

p:eq(0) - select only the first paragraph.
a:eq(4) - select the fifth 'anchor' tag on the page.
.menu-item:eq(3) - select only the forth element that contains the 'menu-item' class.

Combined selectors

h1, p - select every h1 tag AND every paragraph tag.
h3.subtitle - select every h3 tag that contains a 'subtitle' class.
h3:eq(0), a.news-link - select the first h3 tag AND every anchor tag that has the 'news-link' class.

No comments:

Post a Comment