2024-06-17 CSS Input Field Label Animation

2024-06-17 CSS Input Field Label Animation

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript 系列三:練習4 ── 表單驗證</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@100..900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./js_form_validation.css">
</head>
<body>
<div class="container">
<form action="" method="get" >
<div class="header">註冊帳戶
<hr>
</div>

<input type="text" name="NickName" id="nick-name" required>
<div class="labelline">暱稱</div>
<div class="err err-nick-name">
*不能為空白、必須在40字以內
</div>

<input type="email"
name="Email" id="email" required>
<div class="labelline">Email 電子郵件</div>
<div class="err err-email">*不能為空白、必須包含 @ 符號</div>

<input type="password"
name="current-password" id="current-password" required>
<div class="labelline">密碼</div>
<div class="err err-password">
* 不能為空白、必須在8字以上、必須在100字以內
</div>

<div class="button-container">
<button class="submit" type="submit" onclick="btn_submit(event)">註冊

<div class="toast-success">
✅ 註冊成功!可以查看 Email 確認細節!
</div>

</button>

</div>
</form>
</div>


<script src="./js_form_validation.js"></script>

</body>
</html>
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
    /* Hex Color Code 
#ebcbbb 膚色
#6c999a tiffiny綠
#0e2222 深藍色
#DF3079 粉色

*/
*{
font-family: "Noto Sans TC", sans-serif;
}
body{
display: flex;
justify-content: center;
align-items:center;
min-height: 100vh; /* 要設定高度 align-items 才有效 */
background-color: #ebcbbb ;
}
.container{
display: flex;
justify-content: center;
align-items: center;
color: #0e2222;
width: 540px;
height: 450px ;
background: #6c999a;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
position: relative;
}
.header{
text-align: center;
font-size: 1.5em;
margin-bottom: 35px;
}

input{
margin-top: 30px;
width: 450px;
height: 40px ;
font-size: 18px;
background: transparent;
transition: 0.1s ease;
border: 1px solid #0e2222;
border-radius: 5px;
color: #212121;
}


.labelline{
position: absolute;
background: #6c999a;
margin-top: -33px;
margin-left: 5px;;
transition: 0.2s ease;
}

input:focus{
outline: none; /* 不要秀出邊框 */

}

input:focus + .labelline ,
input:valid + .labelline{
/* color: #0e2222; */
color: #DF3079;
padding: 0.12px;
transform: translate(1.5px, -21px) scale(0.9);
z-index: 1111;
}

.err{
visibility: hidden;
color:#f00;
font-size: 13px;
}

/* button 要變更位置,需要在外面包一層wrap .button-container */
.button-container {
display: flex;
justify-content:end;
width: 100%;
margin-top: 20px;

}
button.submit {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #0056b3 ;
color: white;
border: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}

button.submit:hover {
background-color: #0e2222;
}


.toast-success{
display:none;
font-size:15px;
position: absolute;
background-color: #C6F6D5;
color: #276749;
border-radius: 15px;
padding: 12px 15px;
top:0;
left: 20px;

}

.toast-success {
animation: my_message 5s;
opacity:0;
}

@keyframes my_message{
from {
top: -20px; opacity: 100;}
to{ top: -80px;
opacity: 0;}

}