Skip to content

Commit 16c91cd

Browse files
authored
fix: update defined-pseudo-class example (#86)
1 parent ec4f1e6 commit 16c91cd

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-28
lines changed

defined-pseudo-class/index.html

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,76 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8">
4+
<meta charset="utf-8" />
55
<title>:defined demo</title>
6-
<script src="main.js" defer></script>
76
<style>
8-
p {
9-
background: yellow;
7+
custom-element {
8+
display: block;
9+
border: 5px dashed grey;
10+
border-radius: 1rem;
11+
height: 100px;
12+
width: 400px;
13+
padding: 1rem;
14+
position: relative;
15+
user-select: none;
1016
}
1117

12-
simple-custom {
13-
background: cyan;
18+
code {
19+
background: #ccc;
1420
}
1521

16-
:defined {
17-
font-style: italic;
22+
#btn {
23+
margin-top: 1rem;
24+
cursor: pointer;
1825
}
1926

20-
simple-custom:not(:defined) {
21-
display: none;
27+
custom-element:not(:defined) {
28+
border-color: grey;
29+
color: grey;
2230
}
2331

24-
simple-custom:defined {
25-
display: block;
32+
custom-element:defined {
33+
background-color: wheat;
34+
border-color: black;
35+
color: black;
36+
}
37+
38+
/* show loading message */
39+
custom-element:not(:defined)::before {
40+
content: "Loading...";
41+
position: absolute;
42+
inset: 0 0 0 0;
43+
align-content: center;
44+
text-align: center;
45+
font-size: 2rem;
46+
background-color: white;
47+
border-radius: 1rem;
48+
}
49+
50+
/* remove the loading message */
51+
custom-element:defined::before {
52+
content: "";
2653
}
2754
</style>
2855
</head>
2956
<body>
30-
<h1><code>:defined</code> demo</h1>
3157

32-
<simple-custom text="Custom element example text"></simple-custom>
58+
<custom-element>
59+
<p>
60+
Loaded content: Lorem ipsum tel sed tellus eiusmod tellus. Aenean.
61+
Semper dolor sit nisi. Elit porttitor nisi sit vivamus.
62+
</p>
63+
</custom-element>
64+
<button id="btn">define the <code>&lt;custom-element&gt;</code></button>
65+
66+
<script>
67+
const btn = document.querySelector("#btn");
3368

34-
<p>Standard paragraph example text</p>
69+
btn.addEventListener("click", () => {
70+
customElements.define("custom-element", class extends HTMLElement {});
71+
btn.remove();
72+
});
73+
</script>
3574

3675
</body>
3776
</html>

defined-pseudo-class/main.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)