我已经创建了一个表单,其中包含两个字段:姓名和电子邮件,它们的输入类型为文本,并且在只读格式下。当我尝试运行这段代码时,输出结果与文本值和文本字段重叠。
以下是我的代码:
以下是我的代码:
$(document).ready(function() {
$('input').blur(function() {
// check if the input has any value (if we've typed into it)
if ($(this).val())
$(this).addClass('used');
else
$(this).removeClass('used');
});
});
/* form starting stylings ------------------------------- */
.group {
position: relative;
margin-bottom: 45px;
}
input {
font-size: 18px;
padding: 10px 10px 10px 5px;
display: block;
width: 300px;
border: none;
border-bottom: 1px solid #757575;
}
input:focus {
outline: none;
}
label {
color: #999;
font-size: 18px;
font-weight: normal;
position: absolute;
pointer-events: none;
left: 5px;
top: 10px;
transition: 0.2s ease all;
}
/* active state */
input:focus~label,
input:valid~label {
top: -20px;
font-size: 14px;
color: #5264AE;
}
.bar {
position: relative;
display: block;
width: 300px;
}
.bar:before,
.bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: #5264AE;
transition: 0.2s ease all;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
/* active state */
input:focus~.bar:before,
input:focus~.bar:after {
width: 50%;
}
.highlight {
position: absolute;
height: 60%;
width: 100px;
top: 25%;
left: 0;
pointer-events: none;
opacity: 0.5;
}
/* active state */
input:focus~.highlight {
animation: inputHighlighter 0.3s ease;
}
/* ANIMATIONS ================ */
@keyframes inputHighlighter {
from {
background: #5264AE;
}
to {
width: 0;
background: transparent;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form>
<br/>
<br/>
<div class="group">
<input type="text" readonly value="shruthi">
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="text" readonly value="shruthi@gmail.com">
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
但是我的期望输出是,我想要一个没有重叠文本字段和文本值的表单。
我不知道我的代码有什么问题。可以有人帮忙吗?