-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulticol-gap.html
More file actions
54 lines (48 loc) · 1.77 KB
/
Copy pathmulticol-gap.html
File metadata and controls
54 lines (48 loc) · 1.77 KB
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo</title>
<link rel="stylesheet" href="style.css">
<style>
.article {
column-count: 3;
column-gap: var(--gap, 2rem);
column-rule: 16px solid #c00;
}
.article p {
margin: 0 0 1em;
}
output {
font-variant-numeric: tabular-nums;
}
</style>
</head>
<body>
<div class="controls">
<label>
column-gap:
<input type="range" id="gap" min="4" max="80" step="1" value="32">
<output id="gapValue">32px</output>
</label>
<p class="note">column-rule-widthは16pxに固定しています。column-gapを狭くしていくと、線がテキストに重なります。</p>
</div>
<div class="article" id="article">
<p>column-ruleの線は隙間の中央に描かれます。線がcolumn-gapより太いと、はみ出した部分がそのままコンテンツに重なってしまいます。</p>
<p>スライダーでcolumn-gapを狭くしてみてください。16pxを下回ったあたりから、線がテキストに食い込んでいきます。</p>
<p>線とテキストのあいだの間隔は、実質(column-gap - column-rule-width) / 2です。ですので、column-gapとcolumn-rule-widthはセットで管理するのが安全です。</p>
</div>
<script>
const gap = document.getElementById("gap");
const article = document.getElementById("article");
const gapValue = document.getElementById("gapValue");
const update = () => {
article.style.setProperty("--gap", `${gap.value}px`);
gapValue.textContent = `${gap.value}px`;
};
gap.addEventListener("input", update);
update();
</script>
</body>
</html>