我制作了这些表格,使标签在填充后可见。我使用绝对定位,这给出了填充左边是一个固定距离的问题,它不依赖于标签名的长度。 您可以在此处查看问题:https://jsfiddle.net/eo4uop7g/
我试图弄清楚其他一些解决方案,但没有任何运气。也许你们中的一些人知道如何使这更灵活?
$(document).ready(function() {
$('input').each(function() {
$(this).on('focus', function() {
$(this).parent('.userbasic article').addClass('active');
});
$(this).on('blur', function() {
if ($(this).val().length == 0) {
$(this).parent('.userbasic article').removeClass('active');
}
});
if ($(this).val() != '') $(this).parent('.userbasic article').addClass('active');
});
});
form input {
height: 45px;
width: 100%;
transition: .1s all linear;
}
.userbasic {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.userbasic article {
flex: 1;
margin: 0 .5rem 1rem;
position: relative;
}
.userbasic article:first-child {
margin-left: 0;
}
.userbasic article:last-child {
margin-right: 0;
}
.userbasic article.active input {
padding-left: 80px;
}
.userbasic article.active label {
top: 0;
left: 0;
height: 50px;
padding: 18px;
color: white;
background: #777;
box-sizing: border-box;
}
.userbasic label {
position: absolute;
color: #777;
top: 18px;
left: 15px;
font-size: 12px;
transition: .1s all linear;
cursor: text;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="userbasic">
<article>
<label for="i4">Zip</label>
<input id="i4" type="text">
</article>
<article>
<label for="i5">Very long name</label>
<input id="i5" type="Number">
</article>
</form>
答案 0 :(得分:1)
不使用绝对定位而是使用标签的静态/相对位置,并使用flex将输入字段旁边的标签定位。这样,当文本较长时,您的标签会缩小输入
Ext.getCmp('usernameID').setValue(Fromdate);
&#13;
$(document).ready(function() {
$('input').each(function() {
$(this).on('focus', function() {
$(this).parent('.userbasic article').addClass('active');
});
$(this).on('blur', function() {
if ($(this).val().length == 0) {
$(this).parent('.userbasic article').removeClass('active');
}
});
if ($(this).val() != '') $(this).parent('.userbasic article').addClass('active');
});
});
&#13;
* {
box-sizing: border-box;
}
form input {
height: 45px;
flex: 1;
transition: 100ms all linear;
border: 1px solid #555;
border-left: none;
}
.userbasic {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.userbasic article {
flex: 1;
margin: 0 .5rem 1rem;
position: relative;
display: flex;
}
.userbasic article:first-child {
margin-left: 0;
}
.userbasic article:last-child {
margin-right: 0;
}
.userbasic article.active label {
color: white;
background: #777;
}
.userbasic label {
color: #777;
font-size: 12px;
transition: 100ms all linear;
cursor: text;
height: 45px;
line-height: 45px;
padding: 0 10px;
display: inline-block;
border: 1px solid #555;
border-right: none;
white-space: nowrap;
flex: 0;
}
&#13;