gpt4 book ai didi

javascript - 带有标签的自定义 Material 样式输入不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:28:46 26 4
gpt4 key购买 nike

我创建了一个带有标签的 Material 设计风格的输入表单,这里是一个JSfiddle demo它似乎工作正常,但只有当我在输入标签中添加 required 时它才有效,如果我从输入中删除 required 它停止工作,不知道为什么,有人可以吗进去看看?

提前致谢。

.ttl{
font-size:16px;
margin:10px 0;
}
.form-row:nth-child(1){
margin-top:50px;
}
.form-row {
margin-top: 20px;
margin-bottom: 20px;
float: left;
width: 100%;
position: relative;
}
.form-group input {
height: 2.5rem;
}
.form-group .control-label {
position: absolute;
top: 0.25rem;
pointer-events: none;
padding-left: 0.125rem;
z-index: 1;
color: #696969;
font-size: 1.750rem;
font-weight: normal;
-webkit-transition: all 0.28s ease;
transition: all 0.28s ease;
font-family: 'Montserrat-Regular';
text-align: center;
width: 100%;
}
.form-group .bar {
position: relative;
border-bottom: 0.0625rem solid #999;
display: block;
}
.form-group .bar::before {
content: '';
height: 0.125rem;
width: 0;
left: 50%;
bottom: -0.0625rem;
position: absolute;
background: #40b8f1;
-webkit-transition: left 0.28s ease, width 0.28s ease;
transition: left 0.28s ease, width 0.28s ease;
z-index: 2;
}
.form-group input, .form-group textarea {
display: block;
background: none;
padding: 0.125rem 0.125rem 0.0625rem;
font-size: 1.750rem;
border-width: 0;
border-color: transparent;
line-height: 2;
width: 100%;
color: transparent;
-webkit-transition: all 0.28s ease;
transition: all 0.28s ease;
box-shadow: none;
text-align: center;
}
.form-group select ~ .control-label, .form-group input:focus ~ .control-label, .form-group input:valid ~ .control-label, .form-group input.form-file ~ .control-label, .form-group input.has-value ~ .control-label, .form-group textarea:focus ~ .control-label, .form-group textarea:valid ~ .control-label, .form-group textarea.form-file ~ .control-label, .form-group textarea.has-value ~ .control-label {
font-size: 1.750rem;
color: gray;
top: -2.750rem;
left: 0;
}
.form-group select:focus ~ .bar::before, .form-group input:focus ~ .bar::before, .form-group textarea:focus ~ .bar::before {
width: 100%;
left: 0;
}
<p class="ttl">Without required it doesn't work</p>
<div class="form-row">
<div class="form-group">
<input type="text" name="student">
<label for="input" class="control-label">Label Title here</label>
<i class="bar"></i>
</div>
</div>
<p class="ttl">With required it works</p>
<div class="form-row">
<div class="form-group">
<input required type="text" name="student">
<label for="input" class="control-label">Label Title here</label>
<i class="bar"></i>
</div>
</div>

最佳答案

从输入焦点的样式中删除 .form-group input:valid ~ .control-label

对此的更改

 .form-group select ~ .control-label, .form-group input:focus ~   .control-label, .form-group input.form-file ~ .control-label, .form-group input.has-value ~ .control-label, .form-group textarea:focus ~ .control-label, .form-group textarea:valid ~ .control-label, .form-group textarea.form-file ~ .control-label, .form-group textarea.has-value ~       .control-label {
font-size: 1.750rem;
color: gray;
top: -2.750rem;
left: 0;
}

https://jsfiddle.net/fy577w6b/3/

或者在输入无效时为控件标签添加样式。

关于javascript - 带有标签的自定义 Material 样式输入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40925372/

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