[英]CSS: Transition effect on text input border
How to create transition effect like: 如何创建过渡效果,例如:
http://jsfiddle.net/mfn5nefb/6/ http://jsfiddle.net/mfn5nefb/6/
but for text input
? 但是要input
文字吗?
I tried replace h1
with input
but it does not work. 我尝试用input
替换h1
,但是它不起作用。
You have to change the HTML structure to do the same with input
because you can't use pseudo elements like :after
on an input element (which is an auto closing element) 您必须更改HTML结构以对input
执行相同的操作,因为您不能在输入元素(这是一个自动关闭元素)上使用像:after
这样的伪元素。
HTML 的HTML
<div id="input">
<input type="text" value="CSS IS AWESOME" /><span></span>
</div>
CSS 的CSS
#input {
color: #666;
position: relative;
display: inline-block;
}
span {
position: absolute;
left: 50%;
content: '';
height: 40px;
height: 5px;
background: #f00;
transition: all 0.5s linear;
width: 0;
bottom: -5px;
}
input:hover ~ span {
width: 200px;
margin-left: -105px;
}
.input_container{ display: inline-block; text-align: center; } .awsome_input{ padding: 5px 10px; border: none; background: transparent; display: block; } .awsome_input_border{ display:inline-block; width:0px; height: 2px; background: #FEC938; position: relative; top:-5px; -webkit-transition: all ease-in-out .15s; -o-transition: all ease-in-out .15s; transition: all ease-in-out .15s; } .awsome_input:hover, .awsome_input:active, .awsome_input:focus{ outline: none; } .awsome_input:hover+.awsome_input_border, .awsome_input:active+.awsome_input_border, .awsome_input:focus+.awsome_input_border{ width:100%; }
<div class="input_container"> <input type="text" class="awsome_input" placeholder="What do you think?"/> <span class="awsome_input_border"/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.