How do I disable the resizable property of a textarea?

后端 未结 18 1175
北荒
北荒 2020-11-22 09:56

I want to disable the resizable property of a textarea.

Currently, I can resize a textarea by clicking on the bottom right corner of the

相关标签:
18条回答
  • 2020-11-22 10:38

    CSS 3 has a new property for UI elements that will allow you to do this. The property is the resize property. So you would add the following to your stylesheet to disable resizing of all textarea elements:

    textarea { resize: none; }
    

    This is a CSS 3 property; use a compatibility chart to see browser compatibility.

    Personally, I would find it very annoying to have resizing disabled on textarea elements. This is one of those situations where the designer is trying to "break" the user's client. If your design can't accommodate a larger textarea, you might want to reconsider how your design works. Any user can add textarea { resize: both !important; } to their user stylesheet to override your preference.

    0 讨论(0)
  • 2020-11-22 10:39

    This can be done in HTML easily:

    <textarea name="textinput" draggable="false"></textarea>
    

    This works for me. The default value is true for the draggable attribute.

    0 讨论(0)
  • 2020-11-22 10:39

    I have created a small demo to show how resize properties work. I hope it will help you and others as well.

    .resizeable {
      resize: both;
    }
    
    .noResizeable {
      resize: none;
    }
    
    .resizeable_V {
      resize: vertical;
    }
    
    .resizeable_H {
      resize: horizontal;
    }
    <textarea class="resizeable" rows="5" cols="20" name="resizeable" title="This is Resizable.">
    This is Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
    </textarea>
    
    <textarea class="noResizeable" rows="5" title="This will not Resizable. " cols="20" name="resizeable">
    This will not Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
    </textarea>
    
    <textarea class="resizeable_V" title="This is Vertically Resizable." rows="5" cols="20" name="resizeable">
    This is Vertically Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
    </textarea>
    
    <textarea class="resizeable_H" title="This is Horizontally Resizable." rows="5" cols="20" name="resizeable">
    This is Horizontally Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
    </textarea>

    0 讨论(0)
  • 2020-11-22 10:46

    To disable the resize property, use the following CSS property:

    resize: none;
    
    • You can either apply this as an inline style property like so:

      <textarea style="resize: none;"></textarea>
      
    • or in between <style>...</style> element tags like so:

      textarea {
          resize: none;
      }
      
    0 讨论(0)
  • 2020-11-22 10:46

    You can simply disable the textarea property like this:

    textarea {
        resize: none;
    }
    

    To disable vertical or horizontal resizing, use

    resize: vertical;
    

    or

    resize: horizontal;
    
    0 讨论(0)
  • 2020-11-22 10:49

    To disable resize for all textareas:

    textarea {
        resize: none;
    }
    

    To disable resize for a specific textarea, add an attribute, name, or an id and set it to something. In this case, it is named noresize

    HTML

    <textarea name='noresize' id='noresize'> </textarea>
    

    CSS

    /* Using the attribute name */
    textarea[name=noresize] {
        resize: none;
    }
    /* Or using the id */
    
    #noresize {
        resize: none;
    }
    
    0 讨论(0)
提交回复
热议问题