用HTML + Css3 实现炫酷的输入框效果
warning:
这篇文章距离上次修改已过194天,其中的内容可能已经有所变动。
以下是一个使用HTML和CSS3实现炫酷输入框效果的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cool Input Effect</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #f7f7f7;
}
.container {
width: 100%;
margin: 100px auto;
text-align: center;
}
.input-container {
display: inline-block;
position: relative;
width: 300px;
height: 50px;
margin: 20px;
}
.input-field {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
background: transparent;
border: 1px solid #ccc;
padding: 0 15px;
color: #333;
font-size: 16px;
caret-color: #333;
}
.input-field::-webkit-input-placeholder {
color: transparent;
}
.input-field:-moz-placeholder { /* Firefox 18- */
color: transparent;
}
.input-field::-moz-placeholder { /* Firefox 19+ */
color: transparent;
}
.input-field:-ms-input-placeholder {
color: transparent;
}
.placeholder-text {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
pointer-events: none;
color: #999;
padding: 0 15px;
font-size: 16px;
transition: all 0.2s;
transform: translateY(-25px);
}
.input-container:hover .placeholder-text {
transform: translateY(0);
cursor: text;
}
.underline {
width: 100%;
height: 2px;
position: absolute;
bottom: 0;
left: 0;
background: #333;
transition: all 0.2s;
transform: scaleX(0);
}
.input-container:hover .underline {
transform: scaleX(1);
}
</style>
</head>
<body>
<div class="container">
<div class="input-container">
<input class="input-field" type="text" placeholder="Enter your text">
<div class="placeholder-text">Username</div>
<div class="underline"></div>
</div>
</div>
</body>
</html>
这段代码展示了如何创建一个带有动画效果的输入框。当鼠标悬停在输入框上时,占位符会滑动并显示,同时底部的下划线会出现。这是一个简单的示例,可以根据需要进行样式调整和功能添加。
评论已关闭