Source code

Revision control

Copy as Markdown

Other Tools

Any copyright is dedicated to the Public Domain.
<meta charset="utf-8">
<title>Reference: repeat(auto-fit) with grid-aligned abs.pos.</title>
<link rel="author" title="Mats Palmgren" href="">
<style type="text/css">
html,body {
color:black; background-color:white; font-size:16px; padding:0; margin:0;
.grid {
display: grid;
position: relative;
border: 1px solid;
grid-auto-rows: 30px;
grid-template-columns: [a] repeat(auto-fit, [b] 20px [c]) [d] 20px;
grid-gap: 2px;
width: 160px;
height: 30px;
.c1 { width: 160px; }
.c2 { width: 150px; }
.c3 { width: 140px; }
.p1 { padding-left:5px; }
.t2 { grid-template-columns: [a] repeat(auto-fit, [b] 20px [c]) [d]; }
x {
width: 18px;
border:1px solid;
background: grey;
a {
position: absolute;
left:0; top:0; height:3px; right:0;
background: cyan;
grid-column: -1 / auto;
b {
position: absolute;
left:0; bottom:0; height:3px; right:0;
background: brown;
grid-column: auto / -1;
c {
position: absolute;
left:0; bottom:5px; height:3px; right:0;
background: pink;
grid-column: 6 / auto;
d {
position: absolute;
left:0; bottom:10px; height:3px; right:0;
background: silver;
grid-column: 3 / -2;
e {
position: absolute;
left:0; bottom:15px; height:3px; right:0;
background: magenta;
grid-column: 3 / -1;
f {
position: absolute;
left:0; bottom:20px; height:3px; right:0;
background: orange;
grid-column: auto / -2;
x:first-child {
background: lime;
x:last-child {
background: blue;
.t1 x:last-child {
float { float:left; margin-right:20px; }
.x5 { grid-template-columns: repeat(5,20px); }
.x4 { grid-template-columns: repeat(4,20px); }
.x3 { grid-template-columns: repeat(3,20px); }
.x2 { grid-template-columns: repeat(2,20px); }
.x1 { grid-template-columns: repeat(1,20px); }
.x0 { grid-template-columns: none; }
.c1.t1.x5 a { grid-column:5/auto; }
.c1.t1.x4 a { grid-column:4/auto; }
.c1.t1.x3 a { grid-column:3/auto; }
.c1.t1.x2 a { grid-column:2/auto; }
.c1.t1.x1 a { grid-column:1/auto; }
.c2.t1.x0 a { grid-column:2/auto; }
.c1.t1.x5 c { grid-column:-2/auto; }
.c2.t1.x5 c,.c3.t1.x5 c { grid-column:5/6; }
.c1.t1.x4 c { grid-column:4/auto; }
.c2.t1.x4 c,.c3.t1.x4 c { grid-column:-2/-1; }
.t2.x4 c { grid-column:-1/auto; }
.c1.t1.x3 c, .c1.t1.x2 c, .c1.t1.x1 c { grid-column:-2/auto; }
.c2.t1.x3 c, .c3.t1.x3 c, .c2.t1.x2 c, .c3.t1.x2 c, .c2.t1.x1 c, .c3.t1.x1 c { grid-column:-2/-1; }
.t2.x3 c, .t2.x2 c, .t2.x1 c { grid-column:-1/auto; }
.t2 f { grid-column:auto/-1; }
.c1.t1.x5 e, .c1.t1.x4 e, .c2.t1.x2 e, .c3.t1.x2 e { grid-column:3/-2; }
.c1.t1.x3 e ,.c1.t1.x2 e { grid-column:-2/auto; }
.c1.t1.x1 e { grid-column:1/auto; }
.c2.t1.x1 e,.c3.t1.x1 e { grid-column:1/2; }
.t2.x5 d, .t2.x4 d { grid-column:3/-1; }
.t1.x3 d, .t1.x2 d { grid-column:-2/auto; }
.t2.x2 d, .t2.x1 d { grid-column:-1/auto; }
.t2.x0 d, .t2.x0 c { grid-column:1/auto; }
.c1.t1 b { grid-column:auto/-2; }
<div class="grid c1 t1 x5"><x></x><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c2 t1 x5"><x></x><x></x><x></x><x></x><a></a><b></b><c></c><d></d><e></e><f></f><x></x></div>
<div class="grid c3 t1 x5"><x></x><x></x><x></x><x></x><a></a><b></b><c></c><d></d><e></e><f></f><x></x></div>
<div class="grid c1 t2 x5"><x></x><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c2 t2 x5"><x></x><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c3 t2 x5"><x></x><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c1 t1 x4"><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c2 t1 x4"><x></x><x></x><x></x><a></a><b></b><c></c><d></d><e></e><f></f><x></x></div>
<div class="grid c3 t1 x4"><x></x><x></x><x></x><a></a><b></b><c></c><d></d><e></e><f></f><x></x></div>
<div class="grid c1 t2 x4"><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c2 t2 x4"><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c3 t2 x4"><x></x><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c1 t1 x3"><x></x><x></x><a></a><b></b><f></f><x></x></div>
<div class="grid c2 t1 x3"><x></x><x></x><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c3 t1 x3"><x></x><x></x><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c1 t2 x3"><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c2 t2 x3"><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c3 t2 x3"><x></x><x></x><a></a><b></b><d></d><e></e><f></f><x></x></div>
<div class="grid c1 t1 x2"><x></x><a></a><b></b><f></f><x></x></div>
<div class="grid c2 t1 x2"><x></x><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c3 t1 x2"><x></x><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c1 t2 x2"><x></x><a></a><b></b><f></f><x></x></div>
<div class="grid c2 t2 x2"><x></x><a></a><b></b><f></f><x></x></div>
<div class="grid c3 t2 x2"><x></x><a></a><b></b><f></f><x></x></div>
<div class="grid c1 t1 x1"><a></a><b></b><f></f><x></x></div>
<div class="grid c2 t1 x1"><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c3 t1 x1"><a></a><b></b><c></c><e></e><f></f><x></x></div>
<div class="grid c1 t2 x1"><a></a><b></b><f></f><x></x></div>
<div class="grid c2 t2 x1"><a></a><b></b><f></f><x></x></div>
<div class="grid c3 t2 x1"><a></a><b></b><f></f><x></x></div>
<div class="grid c1 t1 x1 p1"><a></a><b></b><f></f></div>
<div class="grid c2 t1 x1 p1"><a></a><b></b><c></c><e></e><f></f></div>
<div class="grid c3 t1 x1 p1"><a></a><b></b><c></c><e></e><f></f></div>
<div class="grid c1 t2 x0 p1"><a></a><b></b><f></f></div>
<div class="grid c2 t2 x0 p1"><a></a><b></b><f></f></div>
<div class="grid c3 t2 x0 p1"><a></a><b></b><f></f></div>