一旦焦点离开,标签就会恢复原样。我希望输入文本后,即使失去焦点,转换也能保持不变;如果没有输入文本,则恢复为以前的状态。请帮忙添加一段代码,以实现这一点。
<html>
<head>
<title>Index</title>
<style>
body{
font-family:Calibri;
background-color:#FFFCD3;
height:1000px;
width:100%;
margin:0;}
.container{
padding:60px 0 0 0;
margin:auto;
background-color:#B4CDCA;
height:485px;
width:460px;}
h1{
font-size:36px;
padding:5px 50px 5px;
border-width:0 0 0 5px;
border-style:solid;
border-color:red;
font-family:Calibri;
margin:0px 0px 35px;}
form div{
margin:0 60px 50px;
position:relative;}
input{
background-color:transparent;
width:100%;
height:100%;
outline:none;
padding:0;
margin:0;
border-width:0px 0px 2px 0px;
font-size:24px;
line-height:60px;}
.container button{
font-family:Calibri;
margin:0px 114px;
padding:18px 100px;
background-color:transparent;
border:1px solid red;
outline:none;
font-size:24px;}
.container label{
font-size:27px;
position:absolute;
top:0;
line-height:60px;}
input:focus + label{
-webkit-transform:translate(-18px,-24px) scale(0.7,0.7);
transition:ease-in,0.2s;}
</style>
</head>
<body>
<div class="container">
<h1>LOGIN</h1>
<form>
<div>
<input type="text" id="username" name="username" value=""/>
<label for="username">Username</label>
</div>
<div>
<input id="Password" type="password" name="password"/>
<label>Password</label>
</div>
<button>
GO
</button>
</form>
</div>
</body>
</html>