-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid-rule.html
More file actions
72 lines (65 loc) · 1.76 KB
/
Copy pathgrid-rule.html
File metadata and controls
72 lines (65 loc) · 1.76 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!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>
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
}
.grid div {
padding: 12px;
background: #f4f4f4;
border-radius: 4px;
text-align: center;
}
/* 縦方向の隙間だけに線を引く */
.grid.is-column {
column-rule: 2px solid #c00;
}
/* 横方向の隙間だけに線を引く */
.grid.is-row {
row-rule: 2px solid #c00;
}
/* 縦横まとめて線を引く */
.grid.is-both {
rule: 2px solid #c00;
}
</style>
</head>
<body class="needs-gap-decorations">
<div class="controls">
<label><input type="radio" name="mode" value="none">指定なし</label>
<label><input type="radio" name="mode" value="is-column">column-rule</label>
<label><input type="radio" name="mode" value="is-row">row-rule</label>
<label><input type="radio" name="mode" value="is-both" checked>rule(縦横まとめて)</label>
</div>
<div class="grid is-both" id="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
<script>
const grid = document.getElementById("grid");
const modes = ["is-column", "is-row", "is-both"];
document.querySelectorAll('input[name="mode"]').forEach((input) => {
input.addEventListener("change", () => {
grid.classList.remove(...modes);
if (input.value !== "none") {
grid.classList.add(input.value);
}
});
});
</script>
</body>
</html>