【问题标题】:How to do a input box placeholder animation如何做一个输入框占位符动画
【发布时间】:2021-05-17 09:46:51
【问题描述】:

我在一个网站上看到了这个,占位符文本“磅”保留在输入框的顶部。示例:

具体是如何实现的?

  <div id="my-ajax-filter-search">
        <form action="" method="post">
            <label id="label-lg">Weight</label>
            <input type="text" name="search" id="search" value="" >
            <input type="submit" id="submit" name="submit" value="See shipping rates" />
        </form>
        <ul ></ul>
<section class="elementor-section elementor-inner-section elementor-element elementor-element-784a76e1 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="784a76e1" data-element_type="section">
        <div id="ajax_filter_search_results" class="elementor-container elementor-column-gap-no np-wrap">
 
            </div>
</section>
    </div>

CSS:

.input-text {
    min-width: 84px;
}div#my-ajax-filter-search input#search , label#label-lg {
    max-width: 250px;
    margin: 0 auto;
    display: block;
    border-radius: 5px;
}
label#label-lg {
    color: #fff;
    margin-bottom: 6px;
    font-weight: bold;
}
div#my-ajax-filter-search input#submit:focus {
    outline: none;
}
div#my-ajax-filter-search input#submit {
    max-width: 192px;
    display: block;
    width: 100%;
    margin: 15px auto;
    background: #fff;
    font-family: "Montserrat", Sans-serif;
    fill: #373278;
    color: #373278;
    background-color: #ffffff;
    border-style: solid;
    border-width: 1px 1px 1px 1px;
    border-color: #ffffff;
    border-radius: 50px 50px 50px 50px;
    box-shadow: 0px 10px 30px -8px rgb(0 0 0 / 16%);
}

div#my-ajax-filter-search input#submit:hover {
    color: #ffffff;
    background-color: rgba(255,255,255,0);
    border-color: #ffffff;
}


.elementor-price-table__feature-inner input {
    min-width: 1px;
}

.elementor-2 .elementor-element.elementor-element-1257087d .elementor-price-table__feature-inner {
    margin: 0;
}

.elementor-2 .elementor-element.elementor-element-1257087d .elementor-price-table__feature-inner .quantity {
    max-width: 67px;
    margin: 0 auto;
}

.elementor-2 .elementor-element.elementor-element-1257087d .elementor-price-table__feature-inner a.add_cart.button.product_type_simple {
    max-width: 106px;
    margin: 12px auto;
    display: block;
    padding: 17px;
    border-radius: 10px;
    border: 1px solid;
    background: #00a8ff;
    color: #fff;
}

【问题讨论】:

    标签: javascript jquery css ajax


    【解决方案1】:

    您可以使用此代码

    body {
      font-family: sans-serif;
    }
    
    .label-before, .field input:focus + label::before, .field input:valid + label::before {
      line-height: 15px;
      font-size: 12px;
      top: 5px;
      background: #fff;
      padding: 0 6px;
      left: 9px;
    }
    
    
    .field {
      position: relative;
      margin-bottom: 15px;
      margin-top:10px;
      display:inline-block;
    }
    .field label::before {
      content: attr(title);
      position: absolute;
      top: 10px;
      left: 15px;
      line-height: 30px;
      font-size: 14px;
      color: #777;
      transition: 300ms all;
    }
    .field input {
      width: auto;
      height: 50px;
      padding: 0px 15px;
      padding-top:12px;
      box-sizing: border-box;
      font-size: 14px;
      color: #222;
      border: 1px solid #ccc;
      border-radius: 3px;
      text-align: center;
    }
    .field input:focus {
      outline: 0;
      border-color: blue;
    }
    .field input:valid + label::before {
      content: attr(data-title);
    }
    .field input:focus + label::before {
      color: blue;
    }
    <div id="my-ajax-filter-search">
          <form action="" method="post">
            <div class="control-group">
               <div>
                  <label id="label-lg">Weight</label>
               </div>
               <div class="field">
                  <input type="text" required autocomplete="off" name="search" id="search" value="" >
                  <label for="search" title="Pounds" data-title="Pounds"></label>
               </div>
            </div>
                
             <input type="submit" id="submit" name="submit" value="See shipping rates" />
          </form>
            <ul ></ul>
          <section class="elementor-section elementor-inner-section elementor-element elementor-element-784a76e1 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="784a76e1" data-element_type="section">
             <div id="ajax_filter_search_results" class="elementor-container elementor-column-gap-no np-wrap">
     
             </div>
           </section>
    </div>

    【讨论】:

    • 谢谢。看看代码+运行它,不幸的是它没有完成我设定的任务。我熟悉您的代码是如何运行的,我可以做那部分...我以前从未见过的事情是在您输入字段表单时保持“您的文本”显示。
    • 我修改了代码。但我不知道你到底想要什么。稍作改动,您就可以调整设置
    • 谢谢,就是这样。我要把这个添加到我的曲目中,非常漂亮。
    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2021-02-15
    • 1970-01-01
    • 2014-03-31
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    相关资源
    最近更新 更多