Skip to main content

CSS Quickref

CSS 3 Cheat Sheet & Quick Reference

Selectors

Basic Selectors

SelectorDescription
*All elements
divAll div tags
.classnameAll elements with class
#idnameElement with ID
div,pAll divs and paragraphs
#idname *All elements inside #idname

Combinators

SelectorDescription
div.classnameDiv with certain classname
div#idnameDiv with certain ID
div pParagraphs inside divs
div > pAll p tags one level deep in div
div + pP tags immediately after div
div ~ pP tags preceded by div

Attribute Selectors

SelectorDescription
a[target]With a target attribute
a[target="_blank"]Open in new tab
a[href^="/index"]Starts with /index
[class|="chair"]Starts with chair
[class*="chair"]containing chair
[title~="chair"]Contains the word chair
a[href$=".doc"]Ends with .doc
[type="button"]Specified type

Pseudo classes / Pseudo Elements

Pseudoclasses
p::afterAdd content after p
p::beforeAdd content before p
p::first-letterFirst letter in p
p::first-lineFirst line in p
::selectionSelected by user
::placeholderPlaceholder attribute
:rootDocuments root element
:targetHighlight active anchor
div:emptyElement with no children
p:lang(en)P with en language attribute
:not(span)Element that's not a span
a:activeLink in clicked state
a:hoverLink with mouse over it
a:visitedVisited link
Input Pseudo Classes
input:checkedChecked inputs
input:disabledDisabled inputs
input:enabledEnabled inputs
input:focusInput has focus
input:in-rangeValue in range
input:out-of-rangeInput value out of range
input:validInput with valid value
input:invalidInput with invalid value
input:optionalNo required attribute
input:requiredInput with required attribute
input:read-onlyWith readonly attribute
input:read-writeNo readonly attribute
input:indeterminateWith indeterminate state
Structural Pseudo Classes
p:first-childFirst child
p:last-childLast child
p:first-of-typeFirst of some type
p:last-of-typeLast of some type
p:nth-child(2)Second child of its parent
p:nth-child(3n42)Nth-child (an + b) formula
p:nth-last-child(2)Second child from behind
p:nth-of-type(2)Second p of its parent
p:nth-last-of-type(2)...from behind
p:only-of-typeUnique of its parent
p:only-childOnly child of its parent

Fonts

Shorthand

font:italic40014px1.5sans-serif
styleweightsize (required)line-heightfamily (required)

Properties

Property
font-family:<font>
font-size:<size>
letter-spacing:<size>
line-height:<number>
font-weight:<number> / bold / normal
font-style:italic / normal
text-decoration:underline / none
text-align:left / right / center / justify
text-transform:capitalize / uppercase / lowercase

@font-face

Mit @font-face kannst du eine Schriftart direkt von einer URL (z. B. aus deinem Projekt oder einem CDN) laden und ihr einen Namen geben, der dann in CSS mit font-family verwendet werden kann.

@font-face { 
font-family: 'Glegoo';
src: url('../Glegoo.woff');
}

Backgrounds

/* Shorthand: may include zero to one occurances of this values */
background: <attachment> <bg-image> <bg-positon> <bg-size> <repeat-style>
Properties
background:(Shorthand)
background-color:See: Colors
background-image:url(...)
background-position:left/center/right/top/center/bottom
background-size:cover X Y
background-clip:border-box padding-box content-box
background-repeat:no-repeat repeat-x repeat-y
background-attachment:scroll/fixed/local

Examples

background: url(img_man.jpg) no-repeat center; 
background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top repeat;
background: rgb(2,0,36);
background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(13,232,230,1) 35%, rgba(0,212,255,1) 100%);

Animations

animation:bounce300mslinear100msinfinitealternate-reversebothreverse
namedurationtiming-functiondelaycountdirectionfill-modeplay-state
Properties
animation:(shorthand)
animation-name:<name>
animation-duration:<time>ms
animation-timing-function:ease / linear / ease-in / ease-out / ease-in-out
animation-delay:<time>ms
animation-iteration-count:infinite / <number>
animation-direction:normal / reverse / alternate / alternate-reverse
animation-fill-mode:none / forwards / backwards / both / initial / inherit
animation-play-state:normal / reverse / alternate / alternate-reverse

Examples

/* @keyframes duration | timing-function | delay | iteration-count | direction | fill-mode | play-state | name */ 
animation: 3s ease-in 1s 2 reverse both paused slidein;

/* @keyframes duration | timing-function | delay | name */
animation: 3s linear 1s slidein;

/* @keyframes duration | name */
animation: 3s slidein;

animation: 4s linear 0s infinite alternate move_eye; animation: bounce 300ms linear 0s infinite normal;
animation: bounce 300ms linear infinite;
animation: bounce 300ms linear infinite alternate-reverse;
animation: bounce 300ms linear 2s infinite alternate-reverse forwards normal;