您现在的位置是:网站首页> 编程资料编程资料

纯css实现输入框placeholder动效及输入校验CSS实现带箭头的提示框效果【示例代码】CSS使用placeholder-shown伪类实现输入框浮动文字效果CSS实现让同一行文字和输入框对齐的方法CSS实现输入框的周围高亮效果让边框发亮CSS实现 Google Material Design 文本输入框风格(推荐)

2023-10-19 234人已围观

简介 这篇文章主要介绍了纯css实现输入框placeholder动效及输入校验,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

更多精彩内容请关注 https://github.com/abc-club/free-resources

背景

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

答案是肯定的。

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

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

:placeholder-shown兼容性

直接上代码!☺️

源码

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; } 

更多

更多精彩内容请关注 https://github.com/abc-club/free-resources

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

相关内容

-六神源码网