Tôi sẽ tạo cho bạn một trang login đẹp với animation cho button. Đây là code hoàn chỉnh:
html
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-container {
background: rgba(255, 255, 255, 0.95);
padding: 40px;
border-radius: 20px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
width: 400px;
transform: translateY(0);
transition: transform 0.3s ease;
}
.login-container:hover {
transform: translateY(-5px);
}
.login-header {
text-align: center;
margin-bottom: 30px;
}
.login-header h2 {
color: #333;
font-size: 32px;
margin-bottom: 10px;
position: relative;
display: inline-block;
}
.login-header h2::after {
content: '';
position: absolute;
bottom: -5px;
left: 0;
width: 100%;
height: 3px;
background: linear-gradient(90deg, #667eea, #764ba2);
transform: scaleX(0);
transition: transform 0.3s ease;
}
.login-container:hover .login-header h2::after {
transform: scaleX(1);
}
.form-group {
margin-bottom: 20px;
position: relative;
}
.form-group input {
width: 100%;
padding: 12px 15px;
border: 2px solid #e0e0e0;
border-radius: 25px;
font-size: 16px;
transition: all 0.3s ease;
background: #f8f8f8;
}
.form-group input:focus {
outline: none;
border-color: #667eea;
background: white;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}
.form-group label {
position: absolute;
left: 20px;
top: 50%;
transform: translateY(-50%);
color: #999;
transition: all 0.3s ease;
pointer-events: none;
background: white;
padding: 0 5px;
}
.form-group input:focus + label,
.form-group input:not(:placeholder-shown) + label {
top: -10px;
font-size: 12px;
color: #667eea;
}
.login-btn {
width: 100%;
padding: 12px;
border: none;
border-radius: 25px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
font-size: 18px;
font-weight: bold;
cursor: pointer;
position: relative;
overflow: hidden;
transition: all 0.3s ease;
margin-top: 20px;
}
.login-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
transition: left 0.5s ease;
}
.login-btn:hover::before {
left: 100%;
}
.login-btn:hover {
transform: scale(1.05);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}
.login-btn:active {
transform: scale(0.98);
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
.forgot-password {
text-align: center;
margin-top: 20px;
}
.forgot-password a {
color: #667eea;
text-decoration: none;
font-size: 14px;
transition: color 0.3s ease;
}
.forgot-password a:hover {
color: #764ba2;
text-decoration: underline;
}
.social-login {
margin-top: 30px;
text-align: center;
}
.social-login p {
color: #666;
margin-bottom: 15px;
font-size: 14px;
}
.social-buttons {
display: flex;
gap: 10px;
justify-content: center;
}
.social-btn {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2px solid #e0e0e0;
background: white;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
font-size: 18px;
}
.social-btn:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
.social-btn.facebook:hover {
background: #3b5998;
color: white;
border-color: #3b5998;
}
.social-btn.google:hover {
background: #db4437;
color: white;
border-color: #db4437;
}
.social-btn.twitter:hover {
background: #1da1f2;
color: white;
border-color: #1da1f2;
}
/* Loading animation */
.loading {
display: none;
width: 20px;
height: 20px;
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.login-btn.loading-state {
color: transparent;
}
.login-btn.loading-state .loading {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-header">
<h2>Đăng Nhập</h2>
</div>
<form id="loginForm">
<div class="form-group">
<input type="email" id="email" placeholder=" " required>
<label for="email">Email</label>
</div>
<div class="form-group">
<input type="password" id="password" placeholder=" " required>
<label for="password">Mật khẩu</label>
</div>
<button type="submit" class="login-btn" id="loginBtn">
<span class="btn-text">Đăng Nhập</span>
<div class="loading"></div>
</button>
</form>
<div class="forgot-password">
<a href="#">Quên mật khẩu?</a>
</div>
<div class="social-login">
<p>Hoặc đăng nhập với</p>
<div class="social-buttons">
<div class="social-btn facebook">f</div>
<div class="social-btn google">G</div>
<div class="social-btn twitter">t</div>
</div>
</div>
</div>
<script>
// Ripple effect cho button
document.getElementById('loginBtn').addEventListener('click', function(e) {
const button = e.currentTarget;
const ripple = document.createElement('span');
ripple.classList.add('ripple');
const rect = button.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
button.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
// Form submission với loading animation
document.getElementById('loginForm').addEventListener('submit', function(e) {
e.preventDefault();
const button = document.getElementById('loginBtn');
const btnText = button.querySelector('.btn-text');
// Thêm loading state
button.classList.add('loading-state');
button.disabled = true;
// Giả lập xử lý đăng nhập
setTimeout(() => {
button.classList.remove('loading-state');
button.disabled = false;
alert('Đăng nhập thành công!');
}, 2000);
});
// Animation cho social buttons
const socialButtons = document.querySelectorAll('.social-btn');
socialButtons.forEach(btn => {
btn.addEventListener('click', function() {
this.style.transform = 'scale(0.9)';
setTimeout(() => {
this.style.transform = '';
}, 100);
});
});
</script>
</body>
</html>