html - float 标签与预填充输入重叠

标签 html css css-transitions

当输入预填充值时,值与标签重叠。

Overlapping with input

要求是,当 input 预填充值时,它不应与标签重叠。如果用户删除输入值并改变焦点,它应该有过渡效果。

CSS 代码:

.input-float                {
    font-size:14px;
    padding:10px 10px 10px 5px;
    display:block;
    width:100%;
    border:none;
    border-bottom:1px solid #757575;
}
.input-float:focus      { outline:none; }

/* LABEL ======================================= */
.label-float                 {
    color:#999;
    font-size:14px;
    font-weight:normal;
    position:absolute;
    pointer-events:none;
    left:5px;
    top:10px;
    transition:0.2s ease all;
    -moz-transition:0.2s ease all;
    -webkit-transition:0.2s ease all;
}

/* active state */
.input-float:focus ~ .label-float {
    top:-20px;
    font-size:14px;
    color:#5264AE;
}

/* BOTTOM BARS ================================= */
.bar    { position:relative; display:block; width:100%; }
.bar:before, .bar:after     {
    content:'';
    height:2px;
    width:0;
    bottom:1px;
    position:absolute;
    background:#5264AE;
    transition:0.2s ease all;
    -moz-transition:0.2s ease all;
    -webkit-transition:0.2s ease all;
}
.bar:before {
    left:50%;
}
.bar:after {
    right:50%;
}

/* active state */
.input-float:focus ~ .bar:before, .input-float:focus ~ .bar:after {
    width:50%;
}

/* HIGHLIGHTER ================================== */
.highlight {
    position:absolute;
    height:60%;
    width:100px;
    top:25%;
    left:0;
    pointer-events:none;
    opacity:0.5;
}

/* active state */
.input-float:focus ~ .highlight {
    -webkit-animation:inputHighlighter 0.3s ease;
    -moz-animation:inputHighlighter 0.3s ease;
    animation:inputHighlighter 0.3s ease;
}

/* ANIMATIONS ================ */
@-webkit-keyframes inputHighlighter {
    from { background:#5264AE; }
    to  { width:0; background:transparent; }
}
@-moz-keyframes inputHighlighter {
    from { background:#5264AE; }
    to  { width:0; background:transparent; }
}
@keyframes inputHighlighter {
    from { background:#5264AE; }
    to  { width:0; background:transparent; }
}

最佳答案

使用JS触发变化

$("#id").val("新值").trigger("改变");

关于html - float 标签与预填充输入重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52017415/

相关文章:

html - 即使悬停状态消失也保持过渡

html - Jquery 悬停单个元素时触发多个元素

html - 我如何将 css 添加到 drupal 7 View

javascript - 使用 jQuery 将新的 div 容器添加到 div 容器 ID

javascript - 如何在 100% 缩放时获取 DIV 的大小?

html - <a href =""> 元素的最低样式是什么

html - 如何根据 div 中的文本调整 div 大小

javascript - 如何在 javascript 中打开模式而不是手动单击?

jquery - 如果在带有 css 选择器的 jquery 中选择了选项,则显示 div

javascript - CSS 过渡 : Animating between inline styles for "height" style attribute