gpt4 book ai didi

html - 输入控件 float 占位符保持在验证状态

转载 作者:行者123 更新时间:2023-11-28 01:42:49 25 4
gpt4 key购买 nike

我正在尝试实现 float 占位符功能。我编写的代码一切正常,除了当有一个电子邮件字段并且我尝试添加一个不是电子邮件格式的错误条目并且我将焦点从输入框移开时, float 文本仍然出现。您可以查看 codepen link

下面是我的代码:-

.-input-container {
max-width: 540px;
padding-bottom: 30px;
margin-top: 30px;
}

input.-textbox {
width: 100%;
border-radius: 40px;
background-color: #f5f5f5;
border: 1px solid #dddddd;
padding: 16px 30px;
font-size: 16px;
color: #555555;
font-family: OpenSans;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: 1.88;
letter-spacing: normal;
text-align: left;
}

input.-textbox:focus{
outline: none;
box-shadow: none
}

input.-textbox:focus ~ .floating-label,
input.-textbox:not(:focus):valid ~ .floating-label {
top: 8px;
bottom: 10px;
left: 45px;
font-size: 10px;
opacity: 1;
line-height: 2.1;
font-family: OpenSans;
}

input.-textbox ~ .floating-label {
position: absolute;
pointer-events: none;
left: 45px;
top: 18px;
transition: 0.2s ease all;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css" rel="stylesheet"/>
<div class="-input-container col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12 ">
<input type="email" class="-textbox form-control" required="">
<span class="floating-label">E-postadress</span>
</div>

最佳答案

试试这个:

.-input-container {
max-width: 540px;
padding-bottom: 30px;
margin-top: 30px;
}

input.-textbox {
width: 100%;
border-radius: 40px;
background-color: #f5f5f5;
border: 1px solid #dddddd;
padding: 16px 30px;
font-size: 16px;
color: #555555;
font-family: OpenSans;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: 1.88;
letter-spacing: normal;
text-align: left;
&:focus{
outline: none;
box-shadow: none
}
}
<div class="-input-container col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12 ">
<input type="email" class="-textbox form-control" placeholder="E-postadress" required="">
</div>

关于html - 输入控件 float 占位符保持在验证状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50347267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com