纯css如何实现输入框placeholder动效及输入校验

小编给大家分享一下纯css如何实现输入框placeholder动效及输入校验,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

成都创新互联公司服务项目包括观山湖网站建设、观山湖网站制作、观山湖网页制作以及观山湖网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,观山湖网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到观山湖省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

背景

话不多说,我们能否用纯css实现以下效果:

纯css如何实现输入框placeholder动效及输入校验

答案是肯定的。

借助css:placeholder-shown :valid :invalid伪类及html5 input pattern 属性就可以实现

:placeholder-shown伪类目前兼容性如下:

:placeholder-shown兼容性

纯css如何实现输入框placeholder动效及输入校验

直接上代码!☺️

源码

https://jsbin.com/qenucaz/edit?html,css,output

html:




  
  
  JS Bin


  
    
    close
    邮箱

css:

.input-fill{
  width: 100%;
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  padding: 20px 16px 6px;
  border: 1px solid transparent;
   background: #f5f5fa;
  border-radius:10px;
  transition: border-color .25s;
}
.input-fill:placeholder-shown::placeholder {
    color: transparent;
    
}
.input-fill-box {
  width: 50%;
    position: relative;
}
.input-label {
    position: absolute;
    left: 16px; top: 14px;
    pointer-events: none;
    color:#BEC1D9;
   padding: 0 2px;
    transform-origin: 0 0;
    pointer-events: none;
    transition: all .25s;
}
.input-fill:not(:placeholder-shown) ~ .input-label,
.input-fill:focus ~ .input-label {
    transform: scale(0.75) translate(0px, -14px);    
}
.input-fill:focus{
  border: 2px solid #1d31aa;
}

.clear{
  position:absolute;
  top:10px;
  right:-20px;
   display: none;
    transition: all .25s;
}
.input-fill::-ms-clear { display: none; }
.input-fill:not(:placeholder-shown) + .clear { display: inline; }

.input-fill:valid {
 border-color: green;
 box-shadow: inset 5px 0 0 green;
}
.input-fill:not(:placeholder-shown):invalid {
 border-color: red;
 box-shadow: inset 5px 0 0 red;
}

以上是“纯css如何实现输入框placeholder动效及输入校验”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


当前文章:纯css如何实现输入框placeholder动效及输入校验
文章来源:http://myzitong.com/article/pcojjg.html

其他资讯