๐Ÿ“Š We use cookies & analytics to improve your experience. Learn more
Latest

Full-Stack Web Development Bootcamp Module 1 ยท Lesson 2 of 15

0% Exit to course

Module 1 ยท The browser: HTML and CSS Lesson 2 of 15

CSS, flexbox and grid

Learning objective

Flexbox lays out one row or column; grid lays out a whole layout. Knowing which one a problem wants is most of CSS confidence.

The concept

CSS has three jobs and it is worth separating them in your head: layout (where the boxes go), typography (how the text reads) and colour. Flexbox lays out items in ONE direction โ€” a row of buttons, a navbar โ€” and grid places items in TWO directions at once โ€” a page with a sidebar, a gallery of cards.

The properties worth knowing cold: display: flex with justify-content and align-items for alignment; gap instead of margins between items; display: grid with grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)) for a card list that reflows by itself; and max-width with margin: 0 auto to centre a content column. Learn those and half of web layout is done.

CSS
/* A card list that reflows by itself โ€” no media query needed. */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  padding: 18px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #fff;
}
.card h3 { margin: 0 0 6px; }

Common mistakes

The mistake is positioning everything absolutely so it matches one screenshot at one window size. Absolute positioning takes elements out of the flow, so nothing can reflow and the page breaks the moment the window changes. Lay out with flex and grid; reserve positioning for badges and overlays.

Worked example

display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) gives a responsive card grid with no media queries at all.

Your practice task

Build a responsive card grid of six job cards that is three across on a laptop and one across on a phone.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

CSS has three jobs and it is worth separating them in your head: layout (where the boxes go), typography (how the text reads) and colour.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task โ€” do them and the final project brief writes itself.

Next recommended course Data Analytics with SQL & Excel