前端 - 使用css3 :focus 怎样使input的placeholder为空呢?
伊谢尔伦
伊谢尔伦 2017-04-17 12:00:46
[HTML讨论组]

input文本框中有“请搜索”,设置:focus让input框变色,但其中的placeholder文字没有消失,怎样使placeholder为空呢?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(4)
高洛峰
input:focus::-webkit-input-placeholder{
    color:transparent;
}
巴扎黑

如果想要这种效果,可以去掉placeholder,写一个标签模拟placeholder。粗略地写了一下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    p {
        position: relative;
    }

    label {
        position: absolute;
        left: 5px;
        color: #ccc;
    }

    input:focus + label {
        display: none;
    }
    </style>
</head>
<body>
    <p>
        <input type="text">
        <label>sfsdfsaf</label>
    </p>
</body>
</html>
高洛峰

这不是 css 能控制的。

当你有键入文字时,placeholder 自己会消失。

阿神

问一下,代码中的

是啥意思,

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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