* {
/*
* selects any element
*/
}
p {
/*
* selects all paragraph tags
*/
}
a {
/*
* selects all anchor tags
*/
}
.menu {
/*
* selects any element with the class `menu`
*/
}
#footer {
/*
* selects the element with the id `footer`
*/
}
[type="email"] {
/*
* selects any element with the
* `type` attribute `email`
*/
}
[alt] {
/*
* selects any element with an
* `alt` attribute
*/
}
.clearfix::after {
/*
* selects the pseudo-element at the end
* of `.clearfix`
*/
}
::placeholder {
/*
* selects the placeholder in an input
*/
}
input:focus {
/*
* selects inputs when they have focus
*/
}
a:hover {
/*
* selects anchors when they're hovered
*/
}
*
.class
, [attribute]
, pseudo-classes#id
.compound.selectors
.complex .selectors
Inline | ID | Class Attribute Ps-Class |
Tag Ps-Element |
---|---|---|---|
1 | 1 | 1 | 1 |
*
: 0,0,0,0
0,0,0,1
0,0,1,0
0,1,0,0
1,0,0,0
!important
Only if you really know what you're doing…
Finds a single element that matches all conditions of the selector
a.link:hover
Specificity: 0,0,2,1
Finds any matching element in the parent, no matter how deeply nested
.post-body ul
Specificity: 0,0,1,1
>
Finds any matching element nested one level deep inside the parent
#mobile-nav > a
Specificity: 0,1,0,1
+
Finds a matching sibling element immediately after the first element
.site-header + main
Specificity: 0,0,1,1
~
Finds any matching sibling after the first element
h1 ~ p
Specificity: 0,0,0,2
:first-child
:nth-child(2)
:last-child
:nth-last-child(odd)
:first-of-type
:nth-of-type(4n)
:last-of-type
:nth-last-of-type(-n+3)
:hover
:active
:focus
:link
:visited
:target
:checked
:disabled
:invalid
:valid
regex
selector to find things?[attr="string"]
[attr^="string"]
[attr$="string"]
[attr*="string"]
[attr~="string"]
-
: [attr|="string"]
[attr*="String" i]
.nav-item:first-child:nth-last-child(4) {
&,
& ~ * {
/*
* Styles for when there are
* 4 nav-items
*/
}
}
[type="password"][value$="a"] {
background-image:
url("https://bad-guy.com/password/a");
}
[type="password"][value$="b"] {
background-image:
url("https://bad-guy.com/password/b");
}
jdsteinbach