Contenteditable Height transition

后端 未结 2 1491
花落未央
花落未央 2020-12-21 04:39

I have a contenteditable div which grows as the user types.

I now need to transition the height so that when the user presses Enter, the div would grow s

相关标签:
2条回答
  • 2020-12-21 04:59

    @keyframes lineInserted {
      from {
        height: 0;
      }
      to {
        height: 20px; /* cons: hardcoded height */
      }
    }
    div[contenteditable] > div {
      animation-duration: 300ms;
      animation-name: lineInserted;
      transition: height 300ms;
    }
    div[contenteditable] {
      border: 1px solid black;
      max-height: 200px;
      overflow: auto;
      transition: all 300ms ease;
    }
    <div contenteditable>
      Testing
      <br/>one two three
    </div>

    0 讨论(0)
  • 2020-12-21 05:05

    Final solution based on Orland's answer. Thank you, bootstrap!

    HTML

    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    
    <div contenteditable class="form-control">
        Testing <br/> one two three
    </div>
    

    CSS:

    @keyframes lineInserted {  
        from { height: 0; }
        to { height: 20px; }  /* cons: hardcoded height */
    }
    
    div[contenteditable] > div {
        animation-duration: 200ms;
        animation-name: lineInserted;
    }
    
    div[contenteditable]{
        height : auto !important;
        overflow: auto;
        line-height : 20px;
    }
    

    0 讨论(0)
提交回复
热议问题