placeholder-shown
2024-09-28 12:27:35
一般我们常见placeholder伪类选择器用来修改默认样式及文案,忽然发现placeholder-shown伪类选择器,比较官方的解释是
简单来说就是当输入框的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;
}
最新文章
- 浅析CSS中的BFC和IFC
- [原创]JavaEE在CentOS服务器上的部署
- [知识点]Cantor展开
- 软件工程 speedsnail 第二次冲刺4
- 【C# 反射泛型】
- 24种设计模式--装饰模式【Decorator Pattern】
- 延时循环数组 DelayLoops
- Python+selenium打开网页
- 【HTML5】音频视频
- 别人的渗透测试(三)--SQL显错注入
- 使用shiro安全管理
- 解决bug感觉
- 利用VisualVm和JMX远程监控Java进程
- SQL Server 全文索引的硬伤(转载)
- 通过NTP协议进行时间同步
- gson转换对象为json字符串时对特殊字符编码的问题
- 20155334 2016-2017-2 《Java程序设计》第六周学习总结
- java 代理模式,观察者模式
- 巧用CheckedTextView完成自定义radiobutton的listview
- [19/03/25-星期一] 容器_Collection(集合、容器)之Set(集合、安置,无顺序不可重复)