-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.html
More file actions
133 lines (126 loc) · 2.97 KB
/
index.html
File metadata and controls
133 lines (126 loc) · 2.97 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fancy To-Do List</title>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #667eea, #764ba2);
color: #333;
margin: 0;
padding: 0;
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
}
.container {
background: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 20px rgba(0,0,0,0.2);
width: 350px;
}
h1 {
margin-top: 0;
text-align: center;
color: #764ba2;
}
.todo-input {
display: flex;
margin-bottom: 15px;
}
.todo-input input {
flex: 1;
padding: 10px;
border: 2px solid #764ba2;
border-radius: 5px 0 0 5px;
outline: none;
}
.todo-input button {
background: #764ba2;
color: #fff;
border: none;
padding: 10px 15px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background 0.2s;
}
.todo-input button:hover {
background: #5b378c;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
padding: 10px;
margin-bottom: 8px;
background: #f4f4f4;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
transition: background 0.2s;
}
li.completed {
text-decoration: line-through;
color: #999;
background: #e0e0e0;
}
.delete-btn {
background: #e74c3c;
border: none;
color: #fff;
padding: 5px 8px;
border-radius: 50%;
cursor: pointer;
font-size: 14px;
transition: background 0.2s;
}
.delete-btn:hover {
background: #c0392b;
}
</style>
</head>
<body>
<div class="container">
<h1>My To-Do List</h1>
<div class="todo-input">
<input type="text" id="taskInput" placeholder="Add a new task...">
<button onclick="addTask()">+</button>
</div>
<ul id="taskList"></ul>
</div>
<script>
const taskInput = document.getElementById('taskInput');
const taskList = document.getElementById('taskList');
function addTask() {
const taskText = taskInput.value.trim();
if (taskText === "") return;
const li = document.createElement('li');
li.textContent = taskText;
// toggle completed on click
li.addEventListener('click', () => {
li.classList.toggle('completed');
});
// delete button
const delBtn = document.createElement('button');
delBtn.textContent = '×';
delBtn.className = 'delete-btn';
delBtn.addEventListener('click', (e) => {
e.stopPropagation();
li.remove();
});
li.appendChild(delBtn);
taskList.appendChild(li);
taskInput.value = "";
}
taskInput.addEventListener("keypress", function(e) {
if (e.key === "Enter") addTask();
});
</script>
</body>
</html>