06격자 열과 간격
열 개수와 간격을 슬라이더로 잡으면 repeat() 문법이 그대로 적히고, 최소 폭 슬라이더가 auto-fit 을 켜 반응형으로 접습니다.
쓰임상품 목록 칸 나누기, 대시보드 위젯 배치
grid-template-columnsrepeatminmax

<main class="stage">
<div class="gen is-demo" id="gen">
<div class="gen__top">
<div class="gen__preview" aria-hidden="true">
<span class="gen__cell gen__cell--a"></span><span class="gen__cell gen__cell--b"></span>
<span class="gen__cell gen__cell--b"></span><span class="gen__cell gen__cell--a"></span>
<span class="gen__cell gen__cell--a"></span><span class="gen__cell gen__cell--b"></span>
<span class="gen__cell gen__cell--b"></span><span class="gen__cell gen__cell--a"></span>
<span class="gen__cell gen__cell--a"></span><span class="gen__cell gen__cell--b"></span>
<span class="gen__cell gen__cell--b"></span><span class="gen__cell gen__cell--a"></span>
</div>
<div class="gen__grid">
<label class="gen__row">
<span class="gen__lab">최소폭</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="80" max="260" step="20" value="120" data-var="--g-min" aria-label="칸 최소 폭">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
<label class="gen__row">
<span class="gen__lab">간격</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="0" max="24" step="4" value="8" data-var="--g-gap" aria-label="칸 간격">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
</div>
</div>
<div class="gen__out">
<code class="gen__code"><span class="gen__prop">grid-template-columns:</span> repeat(auto-fit, minmax(<span class="gen__v gen__v--min"></span>px, 1fr)); <span class="gen__prop">gap:</span> <span class="gen__v gen__v--gap"></span>px</code>
<button class="gen__copy" type="button" id="copy">복사</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 격자 열과 간격 — auto-fit 반응형 격자의 최소 폭과 간격을 사용자 지정 속성 둘로 잡는다.
// 열 개수 슬라이더가 없는 게 핵심이다: minmax 의 최소 폭이 열 개수를 화면 폭에 맞춰 스스로 정한다.
// 미리보기에서 칸들이 최소 폭이 커지면 한 줄로 펴졌다 작아지면 여러 줄로 접힌다.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-blue-light;
$mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
$line: rgba(255, 255, 255, .16);
$track: rgba(255, 255, 255, .2);
$rail: 4px;
$thumb: 12px;
@property --g-min { syntax: "<integer>"; inherits: true; initial-value: 120; }
@property --g-gap { syntax: "<integer>"; inherits: true; initial-value: 8; }
@include stage($stage-ink);
.gen {
min-width: 0; // stage grid item 의 자동 최소폭(min-content) 을 끊는다 — BD9
--g-min: 120;
--g-gap: 8;
display: flex; flex-direction: column; gap: $sp-3;
box-sizing: border-box; width: min(100%, 400px);
padding: $sp-3; border: 1px solid $line; border-radius: $r-card;
background: rgba(255, 255, 255, .05);
}
.gen__top { display: flex; align-items: center; gap: $sp-3; }
// ── 미리보기 — 카드 12장이 auto-fit 으로 접히고 펴진다
.gen__preview {
flex: 0 0 auto; box-sizing: border-box;
width: 148px; height: 92px; padding: 4px;
border-radius: $r-sm;
background: rgba(0, 0, 0, .28);
display: grid; align-content: start;
grid-template-columns: repeat(auto-fit, minmax(calc(var(--g-min) * 0.32px), 1fr));
gap: 0;
overflow: hidden;
}
// 미리보기 상자가 실제 사용 폭보다 작으므로 계수 0.32 로 눈금만 줄인다 — 칸 수 변화는 그대로 보인다
// 칸 간격은 gap 이 아니라 투명 border 로 준다(297 선례) — 칸 자신의 일부라
// 값이 소수 px 이 되어도 격자 눈금 규칙을 어기지 않는다. 좌우 상하 반씩 나눠 붙인다
.gen__cell {
height: 20px; border-radius: $r-xs; box-sizing: border-box;
border: calc(var(--g-gap) * 0.32px / 2) solid transparent;
background-clip: padding-box;
}
.gen__cell--a { background: $subject-blue; }
.gen__cell--b { background: $subject-pink; }
.gen__grid { flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: $sp-1; }
.gen__row { display: flex; align-items: center; gap: $sp-1; cursor: pointer; }
.gen__lab {
flex: 0 0 auto; width: 42px;
color: $subject-cream;
font-weight: 700; font-size: 10px; line-height: 1.4;
}
.gen__slot {
position: relative; flex: 1 1 auto; min-width: 0;
display: grid; align-items: center; height: 16px;
}
.gen__slot::before {
content: ""; grid-area: 1 / 1;
height: $rail; border-radius: $r-pill; background: $track;
}
.gen__rng {
grid-area: 1 / 1; appearance: none; -webkit-appearance: none;
width: 100%; min-width: 0; height: 16px; margin: 0; background: transparent;
cursor: pointer;
}
.gen__rng::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none;
width: $thumb; height: $thumb; border: 0; border-radius: 50%;
background: transparent;
}
.gen__rng::-moz-range-thumb {
width: $thumb; height: $thumb; border: 0; border-radius: 50%;
background: transparent;
}
.gen__rng:focus-visible { outline: 2px solid $color; outline-offset: 2px; border-radius: $r-pill; }
.gen__thumb {
position: absolute; top: 50%; left: calc(var(--pct) * 1%);
width: $thumb; height: $thumb; margin-top: -($thumb * .5); margin-left: -($thumb * .5);
border-radius: 50%; background: $color;
pointer-events: none;
}
.gen__row:nth-child(1) .gen__thumb { --pct: calc((var(--g-min) - 80) / 180 * 100); }
.gen__row:nth-child(2) .gen__thumb { --pct: calc(var(--g-gap) / 24 * 100); }
.gen__out { display: flex; align-items: flex-start; gap: $sp-2; }
.gen__code {
flex: 1 1 auto; min-width: 0;
padding: $sp-2; border-radius: $r-sm;
background: $subject-ink; color: $subject-cream;
font-family: $mono; font-weight: 500; font-size: 10px; line-height: 1.5;
white-space: nowrap; overflow: hidden;
}
.gen__prop { color: $subject-blue-light; }
.gen__v { font-weight: 700; }
.gen__v--min::after { counter-reset: v var(--g-min); content: counter(v); }
.gen__v--gap::after { counter-reset: v var(--g-gap); content: counter(v); }
.gen__copy {
flex: 0 0 auto;
padding: $sp-2 $sp-3; border: 0; border-radius: $r-sm;
background: $subject-blue-deep; color: $subject-cream;
font-family: inherit; font-weight: 700; font-size: 11px; line-height: 1.4;
cursor: pointer;
}
.gen__copy:focus-visible { outline: 2px solid $color; outline-offset: 2px; }
// ── 격자 미리보기 — 최소 폭이 오가면 칸이 여러 줄로 접혔다 한 줄로 펴진다
@keyframes gMin { 0%, 100% { --g-min: 120; } 40% { --g-min: 240; } 75% { --g-min: 80; } }
@keyframes gGap { 0%, 100% { --g-gap: 8; } 50% { --g-gap: 20; } 85% { --g-gap: 0; } }
.gen.is-demo {
animation-name: gMin, gGap;
animation-duration: $duration;
animation-timing-function: $easing;
animation-iteration-count: infinite;
}
@media (prefers-reduced-motion: reduce) {
.gen.is-demo { animation: none !important; }
}
@media (max-width: 340px) {
.gen { gap: $sp-2; padding: $sp-2; }
.gen__top { gap: $sp-2; }
.gen__preview { width: 116px; height: 84px; }
.gen__code { font-size: 9px; }
}@property --g-min {
syntax: "<integer>";
inherits: true;
initial-value: 120;
}
@property --g-gap {
syntax: "<integer>";
inherits: true;
initial-value: 8;
}
html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.gen {
min-width: 0;
--g-min: 120;
--g-gap: 8;
display: flex;
flex-direction: column;
gap: 12px;
box-sizing: border-box;
width: min(100%, 400px);
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 16px;
background: rgba(255, 255, 255, 0.05);
}
.gen__top {
display: flex;
align-items: center;
gap: 12px;
}
.gen__preview {
flex: 0 0 auto;
box-sizing: border-box;
width: 148px;
height: 92px;
padding: 4px;
border-radius: 8px;
background: rgba(0, 0, 0, 0.28);
display: grid;
align-content: start;
grid-template-columns: repeat(auto-fit, minmax(calc(var(--g-min) * 0.32px), 1fr));
gap: 0;
overflow: hidden;
}
.gen__cell {
height: 20px;
border-radius: 4px;
box-sizing: border-box;
border: calc(var(--g-gap) * 0.32px / 2) solid transparent;
background-clip: padding-box;
}
.gen__cell--a {
background: #2f6df6;
}
.gen__cell--b {
background: #ff9ebb;
}
.gen__grid {
flex: 1 1 auto;
min-width: 0;
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 4px;
}
.gen__row {
display: flex;
align-items: center;
gap: 4px;
cursor: pointer;
}
.gen__lab {
flex: 0 0 auto;
width: 42px;
color: #fff7e6;
font-weight: 700;
font-size: 10px;
line-height: 1.4;
}
.gen__slot {
position: relative;
flex: 1 1 auto;
min-width: 0;
display: grid;
align-items: center;
height: 16px;
}
.gen__slot::before {
content: "";
grid-area: 1/1;
height: 4px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.2);
}
.gen__rng {
grid-area: 1/1;
appearance: none;
-webkit-appearance: none;
width: 100%;
min-width: 0;
height: 16px;
margin: 0;
background: transparent;
cursor: pointer;
}
.gen__rng::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 12px;
height: 12px;
border: 0;
border-radius: 50%;
background: transparent;
}
.gen__rng::-moz-range-thumb {
width: 12px;
height: 12px;
border: 0;
border-radius: 50%;
background: transparent;
}
.gen__rng:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
border-radius: 999px;
}
.gen__thumb {
position: absolute;
top: 50%;
left: calc(var(--pct) * 1%);
width: 12px;
height: 12px;
margin-top: -6px;
margin-left: -6px;
border-radius: 50%;
background: #5b8cf8;
pointer-events: none;
}
.gen__row:nth-child(1) .gen__thumb {
--pct: calc((var(--g-min) - 80) / 180 * 100);
}
.gen__row:nth-child(2) .gen__thumb {
--pct: calc(var(--g-gap) / 24 * 100);
}
.gen__out {
display: flex;
align-items: flex-start;
gap: 8px;
}
.gen__code {
flex: 1 1 auto;
min-width: 0;
padding: 8px;
border-radius: 8px;
background: #17141a;
color: #fff7e6;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
font-weight: 500;
font-size: 10px;
line-height: 1.5;
white-space: nowrap;
overflow: hidden;
}
.gen__prop {
color: #5b8cf8;
}
.gen__v {
font-weight: 700;
}
.gen__v--min::after {
counter-reset: v var(--g-min);
content: counter(v);
}
.gen__v--gap::after {
counter-reset: v var(--g-gap);
content: counter(v);
}
.gen__copy {
flex: 0 0 auto;
padding: 8px 12px;
border: 0;
border-radius: 8px;
background: #0a4fe8;
color: #fff7e6;
font-family: inherit;
font-weight: 700;
font-size: 11px;
line-height: 1.4;
cursor: pointer;
}
.gen__copy:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
@keyframes gMin {
0%, 100% {
--g-min: 120;
}
40% {
--g-min: 240;
}
75% {
--g-min: 80;
}
}
@keyframes gGap {
0%, 100% {
--g-gap: 8;
}
50% {
--g-gap: 20;
}
85% {
--g-gap: 0;
}
}
.gen.is-demo {
animation-name: gMin, gGap;
animation-duration: 2s;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
animation-iteration-count: infinite;
}
@media (prefers-reduced-motion: reduce) {
.gen.is-demo {
animation: none !important;
}
}
@media (max-width: 340px) {
.gen {
gap: 8px;
padding: 8px;
}
.gen__top {
gap: 8px;
}
.gen__preview {
width: 116px;
height: 84px;
}
.gen__code {
font-size: 9px;
}
}var gen = document.getElementById('gen');
var copyBtn = document.getElementById('copy');
var ranges = Array.prototype.slice.call(gen.querySelectorAll('.gen__rng'));
var COPY_LABEL = '복사';
var DONE_LABEL = '복사됨';
// auto-fit + minmax 는 칸 수를 직접 세지 않고 최소 폭이 정하도록 두는 반응형 격자다.
// 그래서 슬라이더는 열 개수가 아니라 최소 폭과 간격만 잡는다 — 칸 수는 화면이 결정한다
function readVar(name) {
return parseInt(getComputedStyle(gen).getPropertyValue(name), 10) || 0;
}
function gridText() {
return 'grid-template-columns: repeat(auto-fit, minmax(' + readVar('--g-min') + 'px, 1fr));\ngap: ' + readVar('--g-gap') + 'px;';
}
// 클립보드는 iframe·http 환경에서 막힐 수 있다 — 거부된 프로미스를 반드시 catch 로 받아 선택 방식으로 떨어진다
function fallbackCopy(text) {
var area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', '');
area.style.position = 'fixed';
area.style.opacity = '0';
document.body.appendChild(area);
area.select();
try { document.execCommand('copy'); } catch (err) { /* 여기까지 막히면 조용히 포기한다 */ }
document.body.removeChild(area);
}
ranges.forEach(function (input) {
input.addEventListener('input', function () {
gen.classList.remove('is-demo');
gen.style.setProperty(input.dataset.var, input.value);
});
input.addEventListener('pointerdown', function () { gen.classList.remove('is-demo'); });
});
copyBtn.addEventListener('click', function () {
gen.classList.remove('is-demo');
var text = gridText();
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).catch(function () { fallbackCopy(text); });
} else {
fallbackCopy(text);
}
copyBtn.textContent = DONE_LABEL;
setTimeout(function () { copyBtn.textContent = COPY_LABEL; }, 1200);
});import { useState, useMemo } from 'react';
import styles from './GridColumns.module.scss';
type Axis = { key: string; label: string; min: number; max: number; step: number };
// ambient 선언에 React 이벤트 제네릭이 없어 로컬 타입으로 받는다 (blog-demo TS7006 항)
type RangeEvt = { target: { value: string } };
const AXES: Axis[] = [
{ key: 'min', label: '최소폭', min: 80, max: 260, step: 20 },
{ key: 'gap', label: '간격', min: 0, max: 24, step: 4 }
];
export type GridColumnsProps = {
duration?: string;
easing?: string;
color?: string;
};
export default function GridColumns({ duration = '2s', easing = 'cubic-bezier(.2, .8, .2, 1)', color = '#5b8cf8' }: GridColumnsProps) {
const [values, setValues] = useState<Record<string, number>>({ min: 120, gap: 8 });
const [live, setLive] = useState(true);
const codeText = useMemo(() => {
return `grid-template-columns: repeat(auto-fit, minmax(${values.min}px, 1fr));\ngap: ${values.gap}px;`;
}, [values]);
const gridStyle = useMemo(() => {
// 미리보기 상자가 실제 사용 폭보다 작으므로 계수 0.32 로 눈금만 줄인다 — 칸 수 변화는 그대로 보인다
return {
gridTemplateColumns: `repeat(auto-fit, minmax(${values.min * 0.32}px, 1fr))`,
gap: `${values.gap * 0.32}px`
} as Record<string, string>;
}, [values]);
const style = {
'--dur-loop': duration,
'--ease-spring': easing,
'--accent': color
} as Record<string, string | number>;
function copy() {
setLive(false);
try {
navigator.clipboard.writeText(codeText);
} catch (err) {
/* 클립보드가 막힌 환경에서는 조용히 넘어간다 */
}
}
return (
<div className={live ? `${styles.gen} ${styles.isDemo}` : styles.gen} style={style}>
<div className={styles.top}>
<div className={styles.preview} aria-hidden="true" style={gridStyle}>
{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((i) => (
<span key={i} className={i % 2 === 0 ? styles.cellA : styles.cellB}></span>
))}
</div>
<div className={styles.grid}>
{AXES.map((axis) => (
<label className={styles.row} key={axis.key}>
<span className={styles.lab}>{axis.label}</span>
<span className={styles.slot}>
<input
className={styles.rng}
type="range"
min={axis.min}
max={axis.max}
step={axis.step}
value={values[axis.key]}
aria-label={axis.label}
onChange={(e: RangeEvt) => {
setLive(false);
setValues((v) => ({ ...v, [axis.key]: Number(e.target.value) }));
}}
/>
<span
className={styles.thumb}
aria-hidden="true"
style={{ left: `${((values[axis.key] - axis.min) / (axis.max - axis.min)) * 100}%` }}
/>
</span>
</label>
))}
</div>
</div>
<div className={styles.out}>
<code className={styles.code}>
<span className={styles.prop}>grid-template-columns:</span> repeat(auto-fit, minmax({values.min}px, 1fr)); <span className={styles.prop}>gap:</span> {values.gap}px
</code>
<button className={styles.copy} type="button" onClick={copy}>복사</button>
</div>
</div>
);
}06 격자 열과 간격 — 측정 누적면적 10.212% · 움직인 프레임 22/23GODRICH 원작 · zip 에 SCSS·React 포함 · css generator 9종 — 슬라이더로 만드는 css 그림자 효과
이 데모가 속한 글
css generator 9종 — 슬라이더로 만드는 css 그림자 효과css generator 는 CSS 값을 손으로 만지는 웹 화면입니다 — 슬라이더를 끌면 코드가 바뀝니다. 그림자·그라디언트·모서리·타이밍 같은 CSS 속성을 눈으로 맞추고, 아래 코드 상자에서 그대로 복사해 씁니다 이 글의 데모 전부 보기


