> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Grid

24 columns with 4px gutters, at every breakpoint.

## Rules

- Make every width a whole number of columns, and start every left edge on a column line.
- The grid is columns only. Vertical space comes from [Spacing](https://ui.fabio.cv/spacing/index.md).
- Work out a span with `span width = (grid width + gutter) × n / 24 − gutter`.
- Centre running text on the middle columns: columns 2 to 23 on mobile, 4 to 21 on tablet and 7 to 18 on desktop.

## Laying a page out

The package has the numbers. The page draws the grid:

```ts
import { style } from '@vanilla-extract/css';

import { Grid, Media } from '@fabiocv/ui/tokens';

export const grid = style({
  display: 'grid',
  gridTemplateColumns: `repeat(${Grid.Columns}, minmax(0, 1fr))`,
  columnGap: Grid.Gutter,
  width: `calc(100% - ${Grid.MobileMargin} * 2)`,
  marginInline: 'auto',
  '@media': {
    [Media.Medium]: {
      width: `calc(100% - ${Grid.TabletMargin} * 2)`,
      maxWidth: Grid.TabletMaxWidth,
    },
    [Media.Large]: {
      width: `calc(100% - ${Grid.Margin} * 2)`,
      maxWidth: 'var(--container-layout-grid)',
    },
  },
});

export const content = style({
  gridColumn: '2 / -2',
  minWidth: 0,
  '@media': {
    [Media.Medium]: { gridColumn: '4 / span 18' },
    [Media.Large]: { gridColumn: '7 / span 12' },
  },
});
```

| Code                  | Value           |
| --------------------- | --------------- |
| `Grid.Columns`        | `24`            |
| `Grid.Gutter`         | `4px`           |
| `Grid.MobileMargin`   | `16px`          |
| `Grid.TabletMargin`   | `32px`          |
| `Grid.Margin`         | `48px`          |
| `Grid.TabletMaxWidth` | `852`, a number |

## Spans on fabio.cv

| Block       | Mobile              | Tablet              | Desktop             |
| ----------- | ------------------- | ------------------- | ------------------- |
| Intro, blog | 22, columns 2 to 23 | 18, columns 4 to 21 | 12, columns 7 to 18 |
| Client tile | A quarter of 22     | A quarter of 18     | 3                   |
| Work column | 24                  | 12                  | 8                   |
| Footer      | 22, columns 2 to 23 | 18, columns 4 to 21 | 12, columns 7 to 18 |

## A drawer's columns

A drawer's sheet spans the 24 columns of the page, and the middle 20 on desktop. What is inside it sits on the same columns.

| On fabio.cv | Mobile                | Tablet                            | Desktop                          |
| ----------- | --------------------- | --------------------------------- | -------------------------------- |
| Sheet       | 24, 48px from the top | 24, 96px from the top             | 20, 96px from the top            |
| Text        | 22, columns 2 to 23   | 10, columns 2 to 11 and 14 to 23  | 8, columns 2 to 9 and 12 to 19   |
| Media       | 24                    | 24 or 12                          | 20 or 10                         |
| Metadata    | 22, under the title   | Ends on the second-to-last column | Ends on the third-to-last column |

The sheet has `2px` of padding, so what is inside reaches past it for its columns to be the page's:

```ts
import { style } from '@vanilla-extract/css';

import { Grid, Media, Spacing } from '@fabiocv/ui/tokens';

export const columns = style({
  display: 'grid',
  gridTemplateColumns: `repeat(${Grid.Columns}, minmax(0, 1fr))`,
  gap: Grid.Gutter,
  marginInline: `calc(${Spacing[2]} * -1)`,
  '@media': {
    [Media.Large]: { gridTemplateColumns: 'repeat(20, minmax(0, 1fr))' },
  },
});
```

Metadata takes its own width, rounded up to whole columns, with one empty column between each, and drops below the title when it does not fit beside it.

# Breakpoints

Two widths split a page into mobile, tablet and desktop.

## Rules

- Style mobile first, then add `Media.Medium` and `Media.Large` for wider screens.
- Import `Media`. Do not write a width into a media query, other than in plain CSS, which cannot import one.
- The page scrolls on the document. Do not wrap it in an inner scroller: on iOS, a tap on the status bar only takes the document back to its top.

## Tokens

| Token                         | Value    | Code           | Use for                                                  |
| ----------------------------- | -------- | -------------- | -------------------------------------------------------- |
| `--breakpoint-layout-tablet`  | `768px`  | `Media.Medium` | Two columns of cards                                     |
| `--breakpoint-layout-desktop` | `1200px` | `Media.Large`  | Three columns of cards, and at least 48px side clearance |

## Containers

| Name                        | Value    | Use for                                                 |
| --------------------------- | -------- | ------------------------------------------------------- |
| `--container-layout-grid`   | `1280px` | The desktop grid                                        |
| `--container-layout-tablet` | `704px`  | The grid at a 768px viewport, minus two 32px edges      |
| `--container-layout-mobile` | `358px`  | The grid at a 390px viewport, minus two 16px edges      |
| `--container-tooltip`       | `240px`  | The maximum width of a tooltip, clamped to the viewport |
| `Grid.TabletMaxWidth`       | `852`    | Where the grid stops growing at wider tablet widths     |

## What changes on any page

|              | Mobile              | Tablet                     | Desktop                     |
| ------------ | ------------------- | -------------------------- | --------------------------- |
| Range        | Below 768px         | 768 to 1199px              | 1200px and up               |
| Grid width   | Viewport − 32px     | Viewport − 64px, max 852px | Viewport − 96px, max 1280px |
| Side edges   | 16px                | 32px                       | 48px minimum                |
| Reference    | 358px grid at 390px | 704px grid at 768px        | 1280px grid at 1728px       |
| Page top gap | 48px                | 48px                       | 48px                        |
| Section gap  | 32px                | 48px                       | 48px                        |

## What changes on fabio.cv

|              | Mobile             | Tablet             | Desktop           |
| ------------ | ------------------ | ------------------ | ----------------- |
| Intro        | Span 22            | Span 18            | Span 12           |
| Client tiles | A quarter, 4 a row | A quarter, 4 a row | Span 3, 4 a row   |
| Work         | Span 24, 1 column  | Span 12, 2 columns | Span 8, 3 columns |
| Footer       | Span 22            | Span 18            | Span 12           |
| Writing row  | 24px               | 32px               | 32px              |
| Writing date | MM/YY              | Month and year     | Month and year    |

See it at https://ui.fabio.cv/layout/.
