Skip to content

Commit 744773b

Browse files
committed
CSS Modules example: overflow
1 parent ac92956 commit 744773b

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

modules/overflow.html

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width" />
6+
<title>Overflow</title>
7+
<style>
8+
article {
9+
display: flex;
10+
gap: 1em;
11+
}
12+
13+
label {
14+
display: block;
15+
white-space: nowrap;
16+
}
17+
18+
pre {
19+
border: 2px dashed crimson;
20+
height: 100px;
21+
width: 20em;
22+
margin-bottom: 3em;
23+
overflow-clip-margin: 1em;
24+
text-align: center;
25+
}
26+
27+
.wide {
28+
width: 40em;
29+
}
30+
31+
::before {
32+
font-weight: bold;
33+
color: white;
34+
background: crimson;
35+
display: inline-block;
36+
width: 100%;
37+
padding: 3px 5px;
38+
box-sizing: border-box;
39+
}
40+
41+
.hidden {
42+
overflow: hidden;
43+
}
44+
.hidden::before {
45+
content: "hidden: ";
46+
}
47+
48+
.clip {
49+
overflow: clip;
50+
}
51+
.clip::before {
52+
content: "clip: ";
53+
}
54+
55+
.scroll {
56+
overflow: scroll;
57+
}
58+
.scroll::before {
59+
content: "scroll: ";
60+
}
61+
62+
.auto {
63+
overflow: auto;
64+
}
65+
.auto::before {
66+
content: "auto: ";
67+
}
68+
69+
.overlay {
70+
overflow: clip;
71+
overflow: overlay;
72+
}
73+
.overlay::before {
74+
content: "overlay (or clip if not supported): ";
75+
}
76+
77+
.visible {
78+
overflow: visible;
79+
}
80+
.visible::before {
81+
content: "visible: ";
82+
}
83+
84+
article:not(:has(pre.clip)) > fieldset > label:nth-of-type(2),
85+
article:not(:has(pre.hidden, pre.scroll, pre.auto, pre.overlay)) fieldset fieldset {
86+
opacity: 20%;
87+
pointer-events: none;
88+
}
89+
</style>
90+
</head>
91+
<body>
92+
<article>
93+
<fieldset><legend>Select options:</legend>
94+
<label><code>overflow</code>:
95+
<select id="overflowValue">
96+
<option>hidden</option>
97+
<option>clip</option>
98+
<option>scroll</option>
99+
<option>auto</option>
100+
<option selected>visible</option>
101+
<option>overlay</option>
102+
</select>
103+
</label>
104+
<label><code>overflow-clip-margin</code>: <input type="number" id="ocm" value="1" min="0" max="10" size="2"><code>em<code></label>
105+
</label>
106+
<label><input type="checkbox" id="wide"> <code>width</code>: <code>20em</code> or <code>40em</code></label>
107+
<fieldset><legend>Scroll programatically:</legend>
108+
<label>ScrollLeft: <input type="range" min="0" max="100" value="0" id="scrollL"></label>
109+
<label>ScrollTop: <input type="range" min="0" max="100" value="0" id="scrollT"></label>
110+
111+
</fieldset>
112+
</fieldset>
113+
<pre class="visible">&nbsp;
114+
Oh, Rubber Duckie, you're the one
115+
You make bath time lots of fun
116+
Rubber Duckie, I'm awfully fond of you
117+
118+
Rubber Duckie, joy of joys
119+
When I squeeze you, you make noise
120+
Rubber Duckie, you're my very best friend, it's true
121+
122+
Oh, every day when I make my way to the tubby
123+
I find a little fella who's cute and yellow and chubby
124+
Rub-a-dub-dubby
125+
126+
<a href="#">Rubber Duckie</a>, you're so fine
127+
And I'm lucky that you're mine
128+
Rubber Duckie, I'm awfully fond of you
129+
</pre>
130+
</article>
131+
<script>
132+
const pre = document.querySelector('pre');
133+
const val = document.getElementById("overflowValue");
134+
const check = document.getElementById("wide");
135+
const ocm = document.getElementById("ocm");
136+
const scrollL = document.getElementById("scrollL");
137+
const scrollT = document.getElementById("scrollT");
138+
139+
val.addEventListener("change", () => {
140+
if (pre.classList.contains("wide")) {
141+
pre.className = `wide ${val.value}`;
142+
} else {
143+
pre.className = `${val.value}`;
144+
}
145+
});
146+
147+
wide.addEventListener("change", () => {
148+
pre.classList.toggle("wide");
149+
});
150+
151+
ocm.addEventListener("change", () => {
152+
pre.style.overflowClipMargin = `${ocm.value}em`;
153+
});
154+
155+
scrollL.addEventListener("change", () => {
156+
scrollExample();
157+
});
158+
scrollT.addEventListener("change", () => {
159+
scrollExample();
160+
});
161+
162+
function scrollExample() {
163+
pre.scrollTo({
164+
top: scrollT.value * 26,
165+
left: scrollL.value * 2,
166+
behavior: "smooth",
167+
});
168+
}
169+
170+
</script>
171+
</body>
172+
</html>

0 commit comments

Comments
 (0)