How to do floating of labels in CSS

后端 未结 6 951
死守一世寂寞
死守一世寂寞 2021-01-30 09:03

I want to display the label of an input inside its input, so that when I click the input, the label will animate and go above the input and change the styles of the input\'s bor

6条回答
  •  孤街浪徒
    2021-01-30 09:58

    Edited @23 Dec 2017

    This will also help you. Considering your image i am asking you want to change text after click?

    input {
      margin: 40px 25px;
      width: 200px;
      display: block;
      border: none;
      padding: 10px 0;
      border-bottom: solid 1px #1abc9c;
      -webkit-transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
      transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
      background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 96%, #1abc9c 4%);
      background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 96%, #1abc9c 4%);
      background-position: -200px 0;
      background-size: 200px 100%;
      background-repeat: no-repeat;
      color: #0e6252;
    }
    
    input:focus, input:valid {
     box-shadow: none;
     outline: none;
     background-position: 0 0;
    }
    
    
    input::-webkit-input-placeholder {
     -webkit-transition: all 0.3s ease-in-out;
     transition: all 0.3s ease-in-out;
    }
    
    input:focus::-webkit-input-placeholder, input:valid::-webkit-input-placeholder {
     color: #1abc9c;
     font-size: 11px;
     -webkit-transform: translateY(-8px);
     transform: translateY(-8px);
     visibility: visible !important;
    }
    
    

提交回复
热议问题