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>
这不是 css 能控制的。
当你有键入文字时,placeholder 自己会消失。
问一下,代码中的
是啥意思,
正文完