summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-grid/subgrid/alignment-in-subgridded-axes-002.html
blob: 68f1b3d43c7af410b43226c7e869b1b1e673213a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Test: Specified alignment properties in subgridded axes</title>
<link rel="author" title="Ethan Jimenez" href="mailto:ethavar@microsoft.com">
<link rel="help" href="https://drafts.csswg.org/css-grid-2/#subgrid-box-alignment">
<link rel="match" href="alignment-in-subgridded-axes-002-ref.html">
<style>
div {
  display: inline-grid;
  gap: 5px;
}

.grid { grid-template: 50px / 50px }
.vlr { writing-mode: vertical-lr }

.subgrid {
  background: gray;
  grid-template: subgrid / subgrid;
}

.item {
  background: orange;
  height: 20px;
  width: 20px;
}

.as { align-self: start }
.ae { align-self: end }
.ac { align-self: center }
.ab { align-self: baseline }

.js { justify-self: start }
.je { justify-self: end }
.jc { justify-self: center }
.jb { justify-self: baseline }
</style>
<div id="wrapper"></div>

<template id="grid">
  <div class="grid">
    <div class="subgrid">
      <div class="item"></div>
    </div>
  </div>
</template>

<script>
"use strict";

let align_properties = ["as", "ae", "ac", "ab"];
let justify_properties = ["js", "je", "jc", "jb"];
let wrapper = document.getElementById("wrapper");

wrapper.style.gridTemplateColumns = `repeat(${justify_properties.length * 2}, 50px)`;

for (let align_self of align_properties) {
  // Add a grid for all combinations of `align-self` and `justify-self`.
  for (let justify_self of justify_properties) {
    let grid = document.getElementById("grid").content.cloneNode(true);
    grid.querySelector(".item").classList.add(align_self, justify_self);
    wrapper.appendChild(grid);
  }

  // Add all combinations again, but make the subgrid orthogonal.
  for (let justify_self of justify_properties) {
    let grid = document.getElementById("grid").content.cloneNode(true);
    grid.querySelector(".item").classList.add(align_self, justify_self);
    grid.querySelector(".subgrid").classList.add("vlr");
    wrapper.appendChild(grid);
  }
}
</script>