- This topic is empty.
-
AuthorPosts
-
August 30, 2018 at 11:00 am #9097David HoangKeymaster
With
@style
, you can give it a custom size and disable the resize feature(resize: none;)
.@Html.TextAreaFor(model => model.YourProperty, new { @style = "width: 90%; height: 180px; resize: none;" })
June 13, 2019 at 12:18 pm #9098David HoangKeymasterI 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>
July 21, 2021 at 4:38 am #9101David HoangKeymastertextarea { resize: none; }
The code above will disable the resizable property of all
<textarea/>
elements in your project. If you want that that is fine, otherwise you would want to use a specific class for your textarea elements..not-resizable { resize: none; }
In your HTML
<textarea class="not-resizable"></textarea>
August 16, 2021 at 2:22 am #9106David HoangKeymasterUse this property
resize: none;
textarea { resize: none; }
August 6, 2022 at 1:51 am #9105David HoangKeymasteryou need to set the below CSS code in your
component.css
textarea { resize: none; }
February 10, 2023 at 11:49 am #9102David HoangKeymasterYou can disable resizeable property of textarea using textarea {resize: none;}
textarea { resize: none; }
June 2, 2023 at 1:43 am #9095David HoangKeymasterIf anyone is looking for a way to this in plain Javascript:
textArea = document.createElement("textarea"); textArea_input.setAttribute("style","resize:none");
Note: Setting the style property this way will overwrite all your prior css style declarations.
August 29, 2023 at 6:23 am #9093David HoangKeymasterYes, you can disable the resizable property of a textarea using CSS. The following code will disable the resizable property of a textarea with the id
my-textarea
:CSS Code:-
textarea#my-textarea { resize: none; }
You can also disable the resizable property of all
textareas
on a page by adding the following code to your CSS stylesheet:CSS Code:-
textarea { resize: none; }
The
resize
property can have three values:none
: The textarea cannot be resized.horizontal
: The text area can only be resized horizontally.vertical
: The text area can only be resized vertically.
The default value of the
resize
property isnone
.In addition to using CSS, you can also disable the resizable property of a textarea using JavaScript. The following code will disable the resizable property of a textarea with the id
my-textarea
:JavaScript Code:-
const textarea = document.getElementById('my-textarea'); textarea.style.resize = 'none';
This code will overwrite any CSS styles that have been applied to the textarea.
To reduce the size of a textarea, you can use the
rows
andcols
attributes in the HTML code. The rows attribute specifies the number ofrows
in the textarea, and thecols
attribute specifies the number of columns. For example, the following code will create a textarea with 10 rows and 50 columns:HTML Code:-
<textarea rows="10" cols="50"></textarea>
You can also use CSS to set the size of a textarea. The following code will set the height and width of a textarea with the id
my-textarea
to 100px and 200px, respectively:CSS Code:-
textarea#my-textarea { height: 100px; width: 200px; }
-
AuthorPosts
- You must be logged in to reply to this topic.