使用css3 :focus 怎样使input的placeholder为空呢?

68次阅读

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

萝卜特洛夫司机

input:focus::-webkit-input-placeholder{
    color:transparent;
}

新しい世界

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

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

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

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

shanyue

这不是 css 能控制的。

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

hsfzxjy

问一下,代码中的使用css3 :focus 怎样使input的placeholder为空呢?

是啥意思,

荷小音

正文完