forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloating_label.html
More file actions
86 lines (85 loc) · 2.45 KB
/
floating_label.html
File metadata and controls
86 lines (85 loc) · 2.45 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Floating Label</title>
<style>
body{
background-color: gray;
margin: 50px;
}
.input-container{
width: 280px;
position: relative;
align-items: center;
}
.label{
position: absolute;
left: 10px;
top: 14px;
transition: all 0.2s;
padding: 0 2px;
z-index: 1;
color: #b3b3b3;
}
.text-input{
padding: 0.8rem;
width: 100%;
height: 100%;
border: 2px solid #2f2c45;
background: #272530;
border-radius: 5px;
font-size: 18px;
outline: none;
transition: all 0.3s;
color: #fff;
}
.label::before{
content: "";
height: 5px;
background: #272530;
position: absolute;
left: 0px;
top: 10px;
width: 100%;
z-index: -1;
}
.text-input:focus{
border: 2px solid #7e4ccb;
}
.text-input:focus+.label, .filled{
top: -10px;
color: white;
font-size: 18px;
font-weight: bold;
}
.text-input::placeholder{
font-size: 16px;
opacity: 0;
transition: all 0.3s;
}
.text-input:focus::placeholder{
opacity: 1;
}
</style>
</head>
<body>
<div class="input-container">
<input type="text" name="username" id="username" class="text-input" autocomplete="off" placeholder="Enter your username" required>
<label for="username" class="label">Username</label>
</div>
<script>
const inputs= document.querySelectorAll('.text-input');
inputs.forEach(element=>{
element.addEventListener("blur",(event)=>{
if(event.target.value != '')
event.target.nextElementSibling.classList.add('filled')
else
event.target.nextElementSibling.classList.remove('filled')
})
})
</script>
</body>
</html>