我已经对我的输入字段进行了浮动标签,如下所示。它的工作也很好。但是,当我删除输入的required
字段时,浮动标签不起作用(尽管我不需要提交required
)。请提出一些解决此问题的方法。当它获得焦点和选择input:not(:focus):valid
选择输入,如果valid input
不是重点当需要删除属性时浮动标签不工作
input:focus~.floating-label,
input:not(:focus):valid~.floating-label {
top: 6px;
bottom: 12px;
left: 20px;
font-size: 11px;
opacity: 1;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: 18px;
text-transform: uppercase;
transition: 0.2s ease all;
color: #b2b2b2;
}
<input type="text" id="floating_name" value="" required/>
<span class="floating-label">Enter</span>
感谢工作fine..But能否请您解释一下,一个空间怎么在这里很重要 – temp
@temp(有效和支架之间)一个lot..Its,您使用的输入:没有(:focus):有效但不要插入限制。当你使用输入时:not(:focus):valid移除这个问题。 – Ehsan
不客气! – Ehsan