vimwiki

Css grid positioning

Terminology

l1 t1 l2  t2  l3    <-- col 
+-----+ +-----+ l1      row
¦ c1  ¦ ¦ c2  ¦ t1       |
¦     ¦ ¦     ¦          ↓
+-----+ +-----+ l2
+-----+ +-----+ 
¦ c3  ¦ ¦ c4  ¦ t2
¦     ¦ ¦     ¦
+-----+ +-----+ l3

c=cell l=line t=track

In the example, the cell 1 is placed in the track column 1 and track row 1, between the vertical lines 1 and 2 and the horizontal lines 1 and 2.

Positioning

To place an item, we use:

We can then moove items, or make them take more than one cell.

div {
  display: grid;
  grid-template: 40px 40px / 40px 40px  ;
}

c1 {
  grid-column-start: 1;
  grid-column-end: 3;
  /* or */
  grid-column: 1 / 3;
}
+-------------+
¦     c1      ¦
¦             ¦
+-------------+
+-----+ +-----+
¦ c2  ¦ ¦ c3  ¦
¦     ¦ ¦     ¦
+-----+ +-----+

Grid area

The grid-area property is a shortend for grid-row-start / grid-column-start / grid-row-end / grid-column-end

item {
  grid-area: 1 / 1 / 3 / 6;
}

Another way to place items is to define a name for it with grid-area, and then in the container, use grid-template-areas to placed it like so:

.container {
  display: grid;
  grid-template: 40px 40px / 40px 40px 
  grid-template-area: "first-item first-item" "second-item ." ;
}

.item1 {
  grid-area: first-item;
}
.item2 {
  grid-area: second-item;
}

An empty cell can be represented by a dot .