标签转换问题
Label transition issue
我是新的html, css和我得到错误时,用户输入无效的输入框,然后特定的输入字段的标签下降,但当用户进入正确的输入,它的工作良好。
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>
<form id="form">
<div class="group">
<input type="text" required id="name" minlength="4">
<span class="highlight"></span>
<span class="bar"></span>
<label class="labeling">Name</label>
</div>
<div class="group">
<input type="email" required id="email">
<span class="highlight"></span>
<span class="bar"></span>
<label class="labeling">Email</label>
</div>
</form>
我已经试过了
<form id="form">
<div class="group">
<input type="text" required id="name" minlength="4">
<span class="highlight"></span>
<span class="bar"></span>
<label class="labeling">Name</label>
</div>
<div class="group">
<input type="email" required id="email">
<span class="highlight"></span>
<span class="bar"></span>
<label class="labeling">Email</label>
</div>
</form>
.group {
margin-top: 40px;
position: relative;
margin-bottom: 45px;
}
input {
font-size: 22px;
padding: 10px 10px 10px 5px;
display: block;
width: 300px;
border: none;
border-bottom: 1px solid #ccc;
}
input:focus {
outline: none;
}
label.labeling {
color: #999;
font-size: 18px;
font-weight: normal;
position: absolute;
pointer-events: none;
left: 5px;
top: 10px;
transition: 0.2s ease all;
}
input:focus ~ label.labeling,
input:valid ~ label.labeling {
top: -20px;
font-size: 14px;
color: #5264AE;
}
.bar {
position: relative;
display: block;
width: 309px;
}
.bar:before,
.bar:after {
content: '';
height: 1px;
width: 0;
bottom: 1px;
position: absolute;
transition: 0.2s ease all;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
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;
}
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px white inset;
}
$(document).ready(function() {
$("#form").validate({
rules: {
name: {
required: true
},
email: {
required: true
}
},
messages: {
minlength: "your name at least 4 characters long",
email: "Please enter a valid email address"
}
});
});
你必须使用一些JS来这里,因为没有:empty
css属性的输入框。(使用:invalid
将意味着您的占位符设置将无法工作!)
使用的css:
input.invalid-input ~ label.labeling {
top: -20px;
font-size: 14px;
color: red;
}
并添加了一些js:
$("input").each(function() {
var $this = $(this);
$this.on("change", function() {
if ($(this).is(':invalid') && $(this).val() != "") {
$(this).addClass("invalid-input");
} else {
$(this).removeClass("invalid-input");
}
});
});
相关文章:
- JavaScript代码问题:我正在将对象转换为数组
- 将jQuery转换为用户脚本的普通Javascript时遇到问题
- 将HTML5模板转换为流星.js,关于js init的问题
- ember.js:转换到相同的路由会产生堆栈溢出问题
- 应用了转换时的D3js排序问题
- Podio问题:Can't将字符串转换为数字
- Javascript/Json日期转换问题
- c# mvc nreco HtmlToPdfConverter 问题将 html 文档转换为 pdf
- 数据互绑定问题:转换器只运行一次,无法绑定元素的 ID
- 为什么这不起作用?我认为这是一个转换问题
- D3-初始化后第一次转换时出现问题
- 使用php解析xml并将其转换为json以与$.ajax一起使用时遇到问题
- SVG到图像的转换问题
- jQuery-图像替换转换〔Safari中的问题〕
- 转换3D的问题
- 设置money.js(用于货币转换器)时出现问题
- 创建/使用简单的美制到公制转换器的问题.(HTML/JavaScript)函数未启动
- 问题通过'这'转换为Javascript函数
- Webkit重绘问题:转换比例+位置变化
- 有问题转换/日期(####)/到MM/dd/yyyy本地与MomentJS