【发布时间】:2020-07-27 08:56:08
【问题描述】:
我正在尝试制作一个浮动标签输入表单。我不知道如何命名。
.form input,
label {
transition: all 500ms;
touch-action: manipulation;
}
.form input {
border: none;
border-bottom: 1px solid #ddd;
height: 1.5em;
margin: 0.5em 0;
width: 100%;
}
.form label {
display: block;
transform-origin: left bottom;
transform: translate(1.5em, -2em);
}
.form input:focus {
border: none;
outline-width: 0;
border-bottom: 1px solid #5fa8d3;
}
.form input:focus+label {
transform: translate(0, -3.4em);
}
<form action="get" class="login-form">
<h1>Log In</h1>
<input type="text" name="username" id="username" autocomplete="none" required />
<label for="username">Username:</label>
<input type="password" name="password" id="password" required />
<label for="password">Password:</label>
</form>
我也试过在.form input:focus + label上加overflow: hidden但是没用,输入的内容被标签覆盖了。
【问题讨论】:
-
你见过这个吗? css-tricks.com/float-labels-css
-
@user3489433 我试过了,但它对我不起作用..这就是我来这里寻求帮助的原因