Search code examples
jqueryhtmlcsssimplemde

Disable resizing of textarea with SimpleMDE


I'm using SimpleMDE as editor on my page. The code is the following:

<!DOCTYPE html>
<head>
    <meta charset="utf-8"/>
    <meta name="description" content=""/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="shortcut icon" href="{% static 'img/favicon.png' %}"/>
    <link rel="stylesheet" href="{% static 'css/reset.css' %}"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
    <link rel="stylesheet" href="{% static 'css/fonts.css' %}"/>
    <link rel="stylesheet" href="{% static 'css/main.css' %}"/>
    <link rel="stylesheet" href="{% static 'css/media.css' %}"/>
    <link rel="stylesheet" href="{% static 'css/jquery.tagit.css' %}"/>
    <link rel="stylesheet" href="{% static 'css/tagit.ui-zendesk.css' %}"/>

    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
    <script src="{% static 'js/markjax.min.js' %}"></script>


</head>
<body>

    <div class="main">
        <div class="container">
            <div class="main_content">
                <div class="row">
                    <div class="main_page_content">
                        <div class="wall">
                            <div class="box_roundbox">
                                <div class="padd_box05">
                                    <form method="post" id="task_create_form">
                                        Description:
                                        <div class="padd_box_top1" name="description">
                                            <textarea name="description" class="task_create_textarea">{{ task.description }}</textarea>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>

        if ($(".task_create_textarea").length) {
            var task_create_textarea_mde = new SimpleMDE({ element : $(".task_create_textarea")[0], spellChecker: false, previewRender: function(plainText, preview) {
                  setTimeout(function() {
                    markjax(plainText, preview);
                  }, 50);
                  return preview.innerHTML;
                } });
        }
    </script>

</body>

CSS classes:

.main  {
    padding-top: 3em;
}
.row  {
    margin-left: 0;
    margin-right: 0;
}
.wall  {
    flex-basis: 0;
    flex-grow: 3;
    margin-right: 2em;
}
.box_roundbox  {
    border: 0.15em solid #AAAAAA;
    border-radius: 0.5em;
}
.padd_box05  {
    padding: 0.5em;
}
.padd_box_top1  {
    padding-top: 1em;
}

My problem is: when I type really long strings in textarea generated by SimpleMDE, it just enlarges uncontrollably. How to disable horizontal resizing of padd_box_top1? I tried resize: none;, but nothing changed.


Solution

  • Try setting a max-width like this:

     .padd_box_top1 {
         max-width: 40%;
     }
    

    This will prevent the textarea from enlarging, if you want a min-width as well you can add that too, just add: min-width: 25%; Change the amount of pixels to whatever you like.