当用户输入无效的电子邮件格式时,带有占位符和无效电子邮件地址的标签样式会合并。
代码是
<form id="myform">
<div class="group">
<input type="text" name ="user" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="email"required >
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
答案 0 :(得分:1)
尝试下面的代码,希望它有效
body{
padding-top:20px;
}
.fieldOuter {
position: relative;
margin: 0 0 30px 0;
font-size: 16px
}
.fieldOuter input {
padding: 10px;
width: 250px;
transition: all 1s;
border: 2px solid #000;
font-size: 17px;
color: #666
}
.fieldOuter label {
position: absolute;
left:0px;
top: 0;
line-height:15px;
transition: all 0.5s;
overflow: hidden;
color: #000;
white-space: nowrap;
z-index: 1;
opacity: 0;
}
.fieldOuter input:focus + label {
opacity: 1;
top: -18px;
}
.fieldOuter input:focus {
outline: none;
border-color: rgba(82, 168, 236, 0.8);
}
&#13;
<div class="fieldOuter">
<input id="Name" placeholder="Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'" type="text" />
<label for="Name">Name</label>
</div>
<div class="fieldOuter">
<input id="LastName" placeholder="Last Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Last Name'"type="text" />
<label for="LastName">Last Name</label>
</div>
&#13;
答案 1 :(得分:1)
input:invalid ~ label {
top:-20px;
font-size:14px;
color:red;
}
将此添加到CSS代码中。电子邮件标签将保持红色,直到其不包含正确的格式