-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure_css_form_validation.html
More file actions
278 lines (250 loc) · 8.03 KB
/
pure_css_form_validation.html
File metadata and controls
278 lines (250 loc) · 8.03 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pure CSS Form Validation</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #6e48aa 0%, #9d50bb 100%);
overflow: hidden;
}
body::before {
content: '';
position: fixed;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 80%);
animation: pulse 15s infinite alternate;
}
@keyframes pulse {
0% { transform: scale(0.8); opacity: 0.3; }
100% { transform: scale(1.2); opacity: 0.5; }
}
form {
width: 360px;
padding: 40px;
box-sizing: border-box;
border-radius: 16px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.2);
position: relative;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
form:hover {
transform: translateY(-5px);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.input-group {
position: relative;
margin-bottom: 30px;
}
input, select {
display: block;
width: 100%;
padding: 14px 14px 14px 50px;
box-sizing: border-box;
font-size: 16px;
border: none;
border-radius: 8px;
background: rgba(255, 255, 255, 0.2);
color: #fff;
transition: all 0.3s ease;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}
input::placeholder, select:invalid {
color: transparent;
}
input:focus, select:focus {
background: rgba(255, 255, 255, 0.3);
box-shadow: 0 0 12px rgba(139, 195, 74, 0.5);
outline: none;
}
input:invalid, select:invalid {
box-shadow: 0 0 12px rgba(244, 67, 54, 0.5);
}
input:valid, select:valid {
background: linear-gradient(135deg, #8BC34A, #7CB342);
color: #fff;
border: 1px solid #689F38;
box-shadow: 0 0 12px rgba(139, 195, 74, 0.5);
}
label {
position: absolute;
top: 14px;
left: 50px;
font-size: 16px;
color: rgba(255, 255, 255, 0.7);
pointer-events: none;
transition: all 0.3s ease;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
background: transparent;
padding: 0 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
input:focus:not(:valid) + label {
top: -10px;
left: 12px;
font-size: 12px;
background: rgba(244, 67, 54, 0.8);
color: white;
padding: 2px 6px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:valid + label {
top: -10px;
left: 12px;
font-size: 12px;
background: linear-gradient(135deg, #8BC34A, #7CB342);
color: white;
padding: 2px 6px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:not(:placeholder-shown) + label,
input:focus + label,
input:valid + label {
top: -10px;
left: 12px;
font-size: 12px;
padding: 2px 6px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:not(:placeholder-shown):not(:valid) + label {
background: rgba(244, 67, 54, 0.8);
color: white;
}
input:valid + label {
background: linear-gradient(135deg, #8BC34A, #7CB342);
color: white;
}
p {
display: none;
font-size: 12px;
margin: 6px 0 0;
color: rgba(255, 255, 255, 0.8);
position: absolute;
top: 100%;
left: 12px;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
input:focus + label + p,
input:invalid:focus + label + p {
display: block;
}
.input-group::before {
content: '';
position: absolute;
left: 15px;
top: 50%;
transform: translateY(-50%);
width: 24px;
height: 24px;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>') no-repeat center;
transition: opacity 0.3s ease;
}
.input-group:nth-child(2)::before {
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" stroke-width="2"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>') no-repeat center;
}
.input-group:nth-child(3)::before {
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" stroke-width="2"><path d="M19 11h-6V7a1 1 0 0 0-2 0v4H5a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2z"/></svg>') no-repeat center;
}
input:focus ~ .input-group::before {
opacity: 0.8;
}
input[type="submit"] {
border: none;
background: linear-gradient(135deg, #F44336, #D32F2F);
color: #fff;
padding: 16px;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
width: 100%;
opacity: 0.85;
cursor: not-allowed;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
overflow: hidden;
}
form:valid input[type="submit"] {
background: linear-gradient(135deg, #8BC34A, #7CB342);
opacity: 1;
cursor: pointer;
box-shadow: 0 4px 15px rgba(139, 195, 74, 0.5);
}
form:valid input[type="submit"]:hover {
transform: scale(1.02);
box-shadow: 0 6px 20px rgba(139, 195, 74, 0.6);
}
form:valid input[type="submit"]:active {
transform: scale(0.98);
box-shadow: 0 2px 10px rgba(139, 195, 74, 0.4);
}
input[type="submit"]::after {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: linear-gradient(to bottom right, rgba(255, 255, 255, 0.3), transparent);
transform: rotate(30deg);
opacity: 0;
transition: opacity 0.3s ease;
}
form:valid input[type="submit"]:hover::after {
opacity: 0.5;
}
</style>
</head>
<body>
<form method="POST" action="#">
<div class="input-group">
<input type="text" name="name" placeholder=" " required>
<label>Full Name</label>
<p>Enter full name (e.g., John Doe)</p>
</div>
<div class="input-group">
<input type="email" name="email" placeholder=" " required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
<label>Email Address</label>
<p>Enter a valid email (e.g., user@domain.com)</p>
</div>
<div class="input-group">
<input type="password" name="password" placeholder=" " required minlength="8" pattern="(?=.*[0-9])(?=.*[a-zA-Z]).{8,}">
<label>Password</label>
<p>Must be 8+ chars with letters & numbers</p>
</div>
<div class="input-group">
<select name="country" required>
<option value="" disabled selected>Select your country</option>
<option value="us">United States</option>
<option value="ca">Canada</option>
<option value="uk">United Kingdom</option>
<option value="in">India</option>
<option value="au">Australia</option>
</select>
<label>Country</label>
<p>Please select your country</p>
</div>
<input type="submit" value="Register">
<!--<input type="submit" value="Register" disabled>-->
</form>
</body>
</html>