<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>输入框标签提示效果</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background-color: #f5f7fa;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
}
.form-container {
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 500px;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: #2c3e50;
}
.form-group {
position: relative;
margin-bottom: 30px;
}
.form-input {
width: 100%;
padding: 15px;
font-size: 16px;
border: 2px solid #e0e0e0;
border-radius: 5px;
transition: all 0.3s ease;
background-color: transparent;
z-index: 1;
position: relative;
}
.form-input:focus {
border-color: #3498db;
outline: none;
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}
.form-label {
position: absolute;
left: 15px;
top: 15px;
color: #95a5a6;
font-size: 16px;
transition: all 0.3s ease;
background-color: white;
padding: 0 5px;
z-index: 0;
}
/* 当input获得焦点或有内容时,label上移并缩小 */
.form-input:focus + .form-label,
.form-input:not(:placeholder-shown) + .form-label {
top: -10px;
left: 10px;
font-size: 12px;
color: #3498db;
z-index: 2;
background-color: white;
}
.submit-btn {
width: 100%;
padding: 15px;
background: linear-gradient(to right, #3498db, #2c3e50);
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.submit-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
.website-link {
display: block;
text-align: center;
margin-top: 30px;
color: #3498db;
font-weight: bold;
text-decoration: none;
transition: color 0.3s;
}
.website-link:hover {
color: #2c3e50;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="form-container">
<h1>用户登录</h1>
<form>
<div class="form-group">
<input type="text" class="form-input" id="username" placeholder=" " required>
<label for="username" class="form-label">用户名</label>
</div>
<div class="form-group">
<input type="password" class="form-input" id="password" placeholder=" " required>
<label for="password" class="form-label">密码</label>
</div>
<button type="submit" class="submit-btn">登录</button>
</form>
</div>
</body>
</html>
输入框标签提示效果
于 2025-04-24 15:24:03 首次发布