我正在努力创建一个与我们联系的表格,如下所示 演示:https://www.teamwork.com/signup 我想做的是,当我在文本框中键入文本时,Textbox Title会移到顶部。 我该怎么做。我在Fiddle写了一些代码。 你能帮助我做这项工作吗? 小提琴:https://jsfiddle.net/3s9ehc0c/
HTML
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="container">
<div class="col-md-5">
<form role="form">
<div class="form-group inner-addon left-addon">
<i class="fa fa-user-o" aria-hidden="true"></i>
<input class="form-control user border-style" name="username" placeholder="Username" />
</div>
<br>
<div class="form-group inner-addon left-addon">
<i class="fa fa-user-o" aria-hidden="true"></i>
<input class="form-control user border-style" name="username" placeholder="Username" />
</div>
</form>
</div>
</div>
CSS
.border-style {
border-width: 0 0 1px 0;
position: relative;
z-index: 2;
border-radius: 0;
height: 40px;
font-size: 17px;
border-color: #e6e6e6;
padding-left: 45px;
background-color: transparent!important;
background-position: left center;
background-repeat: no-repeat;
background-size: 40px 40px;
font-family: inherit;
-webkit-box-shadow: none;
box-shadow: none;
}
.border-style:focus {
box-shadow: none;
}
.form-group2 input:focus+i {
color: blue;
}
.form-group1,
.form-group2 {
display: flex;
align-items: center;
}
.form-group1 i,
.form-group2 i {
order: 1;
padding-right: 0.5em;
}
.form-group input:focus+i {
color: blue;
}
答案 0 :(得分:1)
<i>
元素应放在选择器<input>
的{{1}}元素后面,以匹配HTML上的input:focus+i
元素。
您可以使用CSS <i>
伪元素,:before
函数来引用HTML上的attr()
属性,data-*
和animation
以获得效果。
transition
&#13;
.border-style {
border-width: 0 0 1px 0;
position: relative;
z-index: 2;
border-radius: 0;
height: 40px;
font-size: 17px;
border-color: #e6e6e6;
padding-left: 45px;
background-color: transparent!important;
background-position: left center;
background-repeat: no-repeat;
background-size: 40px 40px;
font-family: inherit;
-webkit-box-shadow: none;
box-shadow: none;
}
.border-style:focus {
box-shadow: none;
}
.form-group2 input:focus+i {
color: blue;
}
.form-group1,
.form-group2 {
display: flex;
align-items: center;
}
.form-group1 i,
.form-group2 i {
order: 1;
padding-right: 0.5em;
}
.form-group input:focus+i {
color: blue;
}
.form-group input:focus+i {
color: blue;
}
.form-group input:focus+i:before {
content: attr(data-placeholder); /* set content */
position: relative;
font-size: 17px;
left: -214px;
top: 0px;
transition: all 1s ease; /* set transition */
animation: placeholder 1s forwards ease; /* set animation */
}
/* do animation stuff at i element */
@keyframes placeholder {
to {
top: -12px;
font-size: 12px;
text-align: center;
left: -204px;
}
}
&#13;