<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.input-container {
position: relative;
width: 400px;
margin-top: 30px;
}
input {
border: none;
outline: none;
border-bottom: 1px solid #757575;
padding: 10px 0;
width: 100%;
}
label {
position: absolute;
top: 5px;
left: 0;
transition: 0.2s ease all;
}
.bar {
position: relative;
}
.bar::before,
.bar::after {
content: '';
position: absolute;
top: 0;
height: 2px;
width: 0;
transition: 0.2s ease all;
background-color: #5264ae;
}
.bar::before {
left: 50%;
}
.bar::after {
right: 50%;
}
input:focus ~ label,
input:valid ~ label {
top: -20px;
}
input:focus ~ .bar::after {
width: 50%;
}
input:focus ~ .bar::before {
width: 50%;
}
</style>
</head>
<body>
<div class="input-container">
<input type="text" id="input" required />
<label for="input">Username</label>
<div class="bar"></div>
</div>
</body>
</html>
用纯css实现material design风格的输入框
最新推荐文章于 2025-03-23 14:43:21 发布