Search code examples
htmlcsstwitter-bootstrapresizecontenteditable

How to make contenteditable div with Bootstrap form-control class auto resize for content?


When I add the "form-control" class to a contenteditable div, the auto resize feature of the div breaks it seems. Try to add new lines to the div and you will see in the snippet.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<div class="container">
<p>
1st with form-control class
</p>
  <div autofocus class="col-md-12 sol-sm-12 form-control" contenteditable="true">Lorem Ipsum Dolor
</div>
<p>
2nd without it
</p>
  <div autofocus class="col-md-12 sol-sm-12" contenteditable="true">Lorem Ipsum Dolor
</div>
</div>


Solution

  • The .form-control element is having a height set to 34px by the 'bootstrap.min.css'. You need to override it using,

    .container .form-control {
      height: auto;
    }
    

    CODEPEN

    Hope this helps.