How to move placeholder to top on focus AND while typing?

前端 未结 7 1249
野的像风
野的像风 2020-11-29 17:38

I want the placeholder to move to the top when the textbox is on focus and also while the user is typing.

I\'m not sure if this is just html/css or any javascript to

7条回答
  •  情话喂你
    2020-11-29 17:48

    .user-input-wrp {
    	position: relative;
    	width: 50%;
    }
    .user-input-wrp .inputText{
    	width: 100%;
    	outline: none;
    	border:none;
    	border-bottom: 1px solid #777;
     	box-shadow: none !important;
    }
    .user-input-wrp .inputText:focus{
    	border-color: blue;
    	border-width: medium medium 2px;
    }
    .user-input-wrp .floating-label {
    	position: absolute;
    	pointer-events: none;
    	top: 18px;
    	left: 10px;
    	transition: 0.2s ease all;
    }
    .user-input-wrp input:focus ~ .floating-label,
    .user-input-wrp input:not(:focus):valid ~ .floating-label{
    	top: 0px;
    	left: 10px;
    	font-size: 13px;
    	opacity: 1;
    }

    The floating label


    Your email address

    Modified the code from @user1846747 a little.

提交回复
热议问题