Move placeholder above the input on focus

后端 未结 4 1604
南方客
南方客 2020-12-14 23:41

I\'m looking for css code that move the placeholder text above the input on focus. I found this code here. This code is perfect but my input tag is wrapped inside <

4条回答
  •  抹茶落季
    2020-12-15 00:31

    If you change html structure then your reference example is work but if you don't want change html structure then you need to write little jQuery. You can check this.

    $(function(){
      $('.blocking-span input').on('focus', function(){
        $(this).parents('.parents-elm').addClass('foucs-content'); // When focus the input area
      });
      $(document).mouseup(function(e){
    		if($(e.target).parents('.blocking-span input').length==0 && !$(e.target).is('.blocking-span input')){
    			$('.parents-elm').removeClass('foucs-content');
    		}
    	});
    });
    div{
      position: relative;
    }
    .blocking-span{
      display: block;
    }
    .blocking-span input{
      border: 1px solid #eaeaea;
      height: 80px;
      padding-top: 30px;
      padding-left: 20px;
      padding-right: 20px;
      width: 100%;
    }
    .floating-label{
      display: inline-block;
      font-size: 15px;
      left: 20px;
      line-height: 20px;
      position: absolute;
      top: -webkit-calc(50% - 10px);
      top: -moz-calc(50% - 10px);
      top: calc(50% - 10px);
      transition: top 0.3s ease-in-out 0s;
    }
    .foucs-content .floating-label{
      top: 10px;
    }
    
    
    Your email address

提交回复
热议问题