一般我们常见placeholder伪类选择器用来修改默认样式及文案,忽然发现placeholder-shown伪类选择器,比较官方的解释是

CSS伪类表示任何显示占位符文本form元素。

简单来说就是当输入框的placeholder内容显示的时候,输入框干嘛干嘛。

兼容性如下,在移动端没什么问题,主要是ie

用这个我们可以实现下面动效

具体代码如下

Html

<div class="input">
<input class="input-fill" placeholder="邮箱">
<label class="input-label">邮箱</label>
</div>

Css

.input{
position: relative;
}
.input-fill{
border: 1px solid #ececec;
outline: none;
padding: 13px 16px 13px;
font-size: 16px;
line-height: 1.5;
width: fit-content;
border-radius: 5px;
}
.input-fill:placeholder-shown::placeholder {
color: transparent;
}
.input-label {
position: absolute;
font-size: 16px;
line-height: 1.5;
left: 16px; top: 14px;
color: #a2a9b6;
padding: 2px;
transform-origin: ;
pointer-events: none;
transition: all .25s;
}
.input-fill:focus{
border: 1px solid #2486ff;
}
.input-fill:not(:placeholder-shown) ~ .input-label,
.input-fill:focus ~ .input-label {
transform: scale(0.75) translate(, -32px);
background-color: #fff;
color: #2486ff;
}

最新文章

  1. 浅析CSS中的BFC和IFC
  2. [原创]JavaEE在CentOS服务器上的部署
  3. [知识点]Cantor展开
  4. 软件工程 speedsnail 第二次冲刺4
  5. 【C# 反射泛型】
  6. 24种设计模式--装饰模式【Decorator Pattern】
  7. 延时循环数组 DelayLoops
  8. Python+selenium打开网页
  9. 【HTML5】音频视频
  10. 别人的渗透测试(三)--SQL显错注入
  11. 使用shiro安全管理
  12. 解决bug感觉
  13. 利用VisualVm和JMX远程监控Java进程
  14. SQL Server 全文索引的硬伤(转载)
  15. 通过NTP协议进行时间同步
  16. gson转换对象为json字符串时对特殊字符编码的问题
  17. 20155334 2016-2017-2 《Java程序设计》第六周学习总结
  18. java 代理模式,观察者模式
  19. 巧用CheckedTextView完成自定义radiobutton的listview
  20. [19/03/25-星期一] 容器_Collection(集合、容器)之Set(集合、安置,无顺序不可重复)

热门文章

  1. jQuery做出手风琴效果
  2. tomcat如何修改发布目录
  3. Python模块-shelve模块
  4. 没办法,SVD就讲的这么好
  5. Java学习路线-知乎
  6. Unity实现支持泛型的事件管理以减少使用object作为参数带来的频繁装拆箱
  7. ubuntu利用包管理器安装Node.JS
  8. C++类和对象的一个简单的实例
  9. 如何使用Hadoop的Partitioner
  10. 22、IDP-ASE