我有一個帶有佔位符的文本輸入。只要您點擊輸入,佔位符就會向上移動並保持爲標題。問題是,當我開始輸入時,標題消失。輸入標題消失
.material-input-login {
margin: 8px 10px;
width: 200px;
/* display: block; */
border: none;
padding: 10px 0;
border-bottom: solid 1px #fff;
-webkit-transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 96%, #fff 4%);
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 96%, #fff 4%);
background-position: -200px 0;
background-size: 200px 100%;
background-repeat: no-repeat;
color: #fff;
}
.material-input-login:focus, .material-input-login:valid {
box-shadow: none;
outline: none;
background-position: 0 0;
}
.material-input-login:focus::-webkit-input-placeholder, .material-input-login:valid::-webkit-input-placeholder {
color: #fff;
font-size: 11px;
-webkit-transform: translateY(-20px);
transform: translateY(-20px);
visibility: visible !important;
}
.material-input-login::-webkit-input-placeholder, .material-button {
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
<input id="searchBox" type="search" placeholder="Search" class="material-input-login" required="">
我不是前端專家,但這是佔位符應該做的事情。也許你可以解決它與價值attr玩。在任何情況下,創建的效果都非常棒! – Memristor