-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper.html
More file actions
156 lines (134 loc) · 3.77 KB
/
paper.html
File metadata and controls
156 lines (134 loc) · 3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<title>Paper</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
html, body {
height:100%;
}
:root {
--x-offset: 8rem;
}
body {
font-family: sans-serif;
}
form {
/* full width/height for margin line */
min-height: 100%;
position: relative;
inset: 0;
/* background trick for adding red line */
background: linear-gradient(red, red);
background-size: 3px 100%;
background-position: 6em 0;
background-repeat: no-repeat;
/* space content off of left side */
padding-left: var(--x-offset);
}
h1 {
margin: 0.25em 0;
font-family: 'Bradley Hand', cursive;
font-size: 2.5em;
}
ul {
counter-reset: list;
}
li {
padding: 1em 0;
margin-left: calc(-1 * var(--x-offset)); /* pull border towards left side */
padding-left: calc(var(--x-offset)); /* pad back off of left side */
list-style: none;
display: flex;
flex-wrap: wrap;
column-gap: 1em;
align-items: center;
border-bottom: 2px solid rgba(0, 0, 255, 0.25);
}
li:first-child {
border-top: 2px solid rgba(0, 0, 255, 0.25);
}
li:last-child .delete {
display: none;
}
/* Add Input # inside label using CSS Counter */
label::before {
counter-increment: list;
content: "Input " counter(list);
}
label {
display: flex;
align-items: center;
column-gap: 0.5em;
flex-wrap: wrap;
}
input, button {
height: 2.25em;
padding: 0 0.5em;
display: block;
box-sizing: border-box;
border: none;
font-size: 1em;
border-radius: 0.25em;
}
input {
border: 1px solid #ddd;
}
button {
background: rgb(11, 94, 215);
color: #fff;
}
button.delete {
background: red;
}
</style>
</head>
<body>
<form>
<h1>
To-Do List:
</h1>
<ul>
<li>
<label>
<input type="text" />
</label>
<button type="button" id="add">Add Item</button>
</li>
</ul>
<p><strong>Note:</strong> This method is not accessible. The input labels are CSS pseudo elements and are not announced by screen readers. Furthermore, the labels are implicitly associated with the inputs via nesting. Labels should always be explicitly defined. Recommend using label/for associations.</p>
<footer>
<a href="https://robertjmccaffery.com/examples.html">Back to Examples</a> | <a href="http://robertjmccaffery.com/">Home</a>
</footer>
</form>
<script>
const btn = document.getElementById("add")
const ul = document.querySelector('ul')
const createDeleteButton = (el) => {
const btn = document.createElement("button")
btn.classList.add('delete')
btn.setAttribute('type', 'button');
btn.textContent = "Remove Item"
btn.addEventListener('click', () => el.remove())
return btn
event.preventDefault();
}
ul.firstElementChild.appendChild(createDeleteButton(ul.firstElementChild))
btn.addEventListener("click", e => {
const input = document.createElement('input')
const li = document.createElement('li')
const label = document.createElement('label')
label.appendChild(input)
li.appendChild(label)
li.appendChild(btn) // move button to last list item
ul.appendChild(li);
li.appendChild(createDeleteButton(li))
})
</script>
</body>
</html>