selector { property: value; property: value; }
body { color: yellow; background-color: black; }
#container { width: 70%; padding: 10px; margin: auto; }
.byline { font-size: 12px; border-bottom: 1px solid #ccc; }
Press → key to advance.
selector { property: value; property: value; }
body { color: yellow; background-color: black; }
#container { width: 70%; padding: 10px; margin: auto; }
.byline { font-size: 12px; border-bottom: 1px solid #ccc; }
img[alt] {}
<img src="image.jpg" alt="accessible">
<img src="image.jpg" title="inaccessible">
[type="date"] {}
<input type="date">
<input type="text">
Note: Multiple attributes work! a[title][href]
p[lang|="en"]{/* <p lang="en-us"> <p lang="en-uk"> */ }
a[title~=more] {/* <a title="want more info about this?">}
a[href^="mailto"] {background-image: url(emailicon.gif);} a[href^="http"]:after {content: " (" attr(href) ")";}
a[href$="pdf"] {background-image: url(pdficon.gif);} a[href$="pdf"]:after {content: " (PDF)";}
input[placeholder] { /* matches any input with a placeholder */} input[type="email"] { /* exact match */} abbr[title~="unicorn"] { /* matches unicorn but not unicorns */} abbr[title|="en"] { /* matches en-us and en-uk */} a[href^="mailto"] { /* starts with */} a[href$="pdf"]{ /* ends in */} abbr[title*="unicorn"] { /* matches unicorn and unicorns */}
E:[att]
/* have the attribute at all */ E:[att="val"]
/* exact */ E:[att~="val"]
/* val is a space separated word */ E:[att|="val"]
/* with a dash */ E:[att^="val"]
/* begins with val */ E:[att$="val"]
/* ends with val */ E:[att*="val"]
/* val is anywhere as a substring */ .
a:link { color:#FF0000; } /* unvisited link */
a:visited { color: green; } /* visited link */
a:hover { color: purple; } /* moused over */
a:focus { color: purple; } /* selected with keyboard*/
a:active { color: blue; } /* activated link */
Based on current state of UI
:enabled :disabled :checked
input:checked { outline: 2px solid red; }
input:checked + label { color: red; }
:valid :invalid :required :optional :in-range :out-of-range :read-only :read-write :default
Example:
input:valid { border: 1px solid green;} input:invalid { border: 1px solid red;} input:required {border-width: 5px;} input:optional {border-width: 10px;} input:out-of-range { background-color: pink;} input:in-range { background-color:lightgreen;}
:nth-child() :nth-last-child() :nth-of-type() :nth-last-of-type() :first-child* :last-child :first-of-type :last-of-type :only-child :only-of-type :root :empty :not(:empty)
:first-child :last-child :first-of-type :last-of-type :only-child :only-of-type
:nth-child(3) :nth-child(3n) :nth-last-child(odd) :nth-of-type(5) :nth-last-of-type(3n+1)
Target element or elements based on argument passed to the selector
tr:first-child, tr:last-child { font-weight: bold; } tr:first-of-type, tr:last-of-type { text-decoration:line-through; } tr:nth-child(even) { background-color: #CCC; } tr:nth-child(3) { color: #CCC; } tr:nth-of-type(odd) { background-color: #FFF; } tr:nth-of-type(4n) { color: #C61800; } tr:nth-of-type(3n-1) { font-style: italic; }
Row 1 |
Row 2 |
Row 3 |
Row 4 |
Row 5 |
Row 6 |
Row 7 |
Row 8 |
Row 9 |
Row 10 |
Pseudo-classes select elements that already exist.
Pseudo-elements create "faux" elements you can style.
::first-line ::first-letterTry it out
::before ::after