Reference

๐ŸŽจ CSS Cheat Sheet

The paint of the house. Print me out!

The pattern

selector {            /* WHO gets painted        */
  property: value;    /* WHAT about them: choice */
}

Rules live inside a <style> tag in the <head>. Every rule needs its { } braces, and every line ends with ;

Selectors โ€” WHO

SelectorPicksExample
h1Every element of that tagh1 { color: purple; }
.cardEverything with class="card".card { padding: 16px; }
#buyThe ONE element with id="buy"#buy { background: gold; }

Properties โ€” WHAT

PropertyChangesExample value
colorText colortomato, #222
background-colorFill color of the boxgold, lavender
font-familyThe letter stylesans-serif
font-sizeLetter size20px
text-alignText positioncenter
paddingSpace INSIDE the box edge16px
marginSpace OUTSIDE the box24px
borderThe frame around the box3px solid purple
border-radiusRound corners12px, 50%=circle

The box model ๐Ÿ“ฆ

โ”Œโ”€ margin โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   space to OTHER boxes
โ”‚  โ”Œโ”€ border โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚   the frame
โ”‚  โ”‚  โ”Œโ”€ padding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚  โ”‚   space inside the frame
โ”‚  โ”‚  โ”‚     content       โ”‚  โ”‚  โ”‚   your text / picture
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Flexbox โ€” the train ๐Ÿš‚

.row {                      /* the PARENT is the track   */
  display: flex;            /* kids line up in a row     */
  gap: 16px;                /* space between train cars  */
  justify-content: center;  /* where the train sits      */
  align-items: center;      /* line up tops and bottoms  */
}

Remember: display: flex goes on the parent, and it moves the children.

Sneaky facts