# Sticky Footer & Card Layouts — CSS Fundamentals: Layout, Flexbox, Grid and Responsive Design

Source: https://www.skillbyai.com/en/css/css-layout-patterns

> Build a sticky footer and a responsive card layout, two patterns used in almost every project.

## Sticky footer

The footer sits at the bottom even when the page content is short — `flex: 1` on `main` pushes it down.

```css
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;
}
```

## A card component

The classic bordered, padded, shadowed content box.

```css
.card {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
```

## Cards + Grid = a gallery

Drop `.card` elements into a `repeat(auto-fit, minmax(...))` grid to get a fully responsive card gallery with almost no extra CSS.

## Final quiz 1 of 8

Final quiz

**Quiz:** Which box-model order is correct from inside out?

- [ ] content, border, padding, margin
- [ ] margin, border, padding, content
- [x] content, padding, border, margin
- [ ] padding, content, border, margin

*Answer:* content, padding, border, margin. Content sits inside padding, then border, then margin.

## Final quiz 2 of 8

Final quiz

**Quiz:** What does box-sizing: border-box change?

- [ ] Width excludes content
- [ ] Margins collapse
- [ ] Borders disappear
- [x] Width includes padding and border

*Answer:* Width includes padding and border. It makes width math predictable.

## Final quiz 3 of 8

Final quiz

**Quiz:** An absolute element positions itself relative to...

- [x] Its nearest positioned ancestor
- [ ] The viewport always
- [ ] Its sibling
- [ ] The body only

*Answer:* Its nearest positioned ancestor. Without one it falls back to the initial containing block.

## Final quiz 4 of 8

Final quiz

**Quiz:** Which is best for a two-dimensional layout?

- [ ] float
- [x] CSS Grid
- [ ] inline
- [ ] table-layout hacks

*Answer:* CSS Grid. Grid handles rows and columns together.

## Final quiz 5 of 8

Final quiz

**Quiz:** Which unit scales with the user's default font size?

- [ ] px
- [ ] pt
- [x] rem
- [ ] cm

*Answer:* rem. rem is relative to the root font size.

## Final quiz 6 of 8

Final quiz

**Quiz:** Which wins: a class selector or an id selector?

- [ ] The class selector
- [ ] Whichever is longer
- [ ] Neither
- [x] The id selector

*Answer:* The id selector. Ids have higher specificity.

## Final quiz 7 of 8

Final quiz

**Quiz:** Which properties are best to animate for performance?

- [x] transform and opacity
- [ ] width and height
- [ ] margin and padding
- [ ] top and left

*Answer:* transform and opacity. They avoid layout and run on the GPU.

## Final quiz 8 of 8

Final quiz

**Quiz:** How do you read a custom property --gap?

- [ ] $gap
- [x] var(--gap)
- [ ] gap()
- [ ] @gap

*Answer:* var(--gap). var() reads custom properties.
