博主信息
博文 81
粉丝 1
评论 0
访问量 146910
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
:placeholder-shown和:not()
有什么是忘不了的的博客
原创
1840人浏览过

今天看了一篇张大神的文章点这里

placeholder-shown伪类实现Material Design占位符交互效果。

我自己看了一遍做的个人理解,以便日后查看。

前后效果图。

1545717884(1).jpg

1545717894(1).jpg

主要就是把input的placeholder颜色设置为通明色。

在用定位吧“邮箱”定位到input里面。然后当input获得焦点时再对“邮箱”重定位。

<div class="input-fill-x">

    <input class="input-fill" placeholder="邮箱">

    <label class="input-label">邮箱</label>

</div>

.input-fill:placeholder-shown::placeholder {

    color: transparent;   //颜色设置为通明色

}

.input-fill {

    height: 40px;

     transition: border-color .25s;

}

.input-fill-x {

    position: relative;

}

.input-label {

    position: absolute;

    left: 16px; top: 12px;

    color: #ddd;

    pointer-events: none;

     transition: all .25s;

}

.input-fill:not(:placeholder-shown) ~ .input-label,

.input-fill:focus ~ .input-label {

    transform: scale(0.75) translate(0, -28px);

    background: #fff;

    color: #2486ff;

}


:not(); 意思就是不对某一个元素上样式。如:

     <h3>123</h3>

     <h3 class="h3">456</h3>

h3:not(.h3){

color: #ddd;

}

效果:1545719000(1).jpg


本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学