黑松山资源网 Design By www.paidiu.com
更多精彩内容请关注 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:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="input-fill-box">
<input class="input-fill" placeholder="邮箱" pattern="^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$" required>
<a href="javascript:" class="clear">close</a>
<label class="input-label">邮箱</label>
</div>
</body>
</html>
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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2025年10月27日
2025年10月27日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]

