2

I have an input type text (also tried with textarea), and I've set its height to like 400px, because I want to make it like a text box. For example like that one that i'm typing in right now. Where the text will wrap on new line and so on. THe problem is that the text only goes in the center and scrolls to the right, instead of wrapping. How do I do it properly?

EDIT: Well i've described it, but if here is the code:

<input type="text" name="message" id="contact_message" pattern=".{10,}">

CSS:

#contact_message {
    width: 400px;
    height:400px;
}

4 Answers4

0

You have two options here: a <textarea> and a <div contenteditable>. I would recommend using a <textarea>.

textarea {
  height: 400px;
  width: 400px;
  word-wrap: break-word;
  outline: 0;
  border: 1px solid black;
  font-family: Arial, Sans-serif;
  font-size: 20pt;
}
<textarea minlength="10">this is some really long text that should break into new lines whenever this crosses 400 pixels wide and go to the new line ehahoitheiahithahihhoghaohhtoihaoiehhnbieoaihtoai</textarea>

You can use a div with contenteditable:

div {
  height: 400px;
  width: 400px;
  font-family: Arial, Sans-serif;
  font-size: 20pt;
  
  }
<div contenteditable>some really long text that should span more than one line when this crosses 400pixels and go into a new line iaoheotheaothoehtoihieothaoihtihiaohtieathioehwaoteahtioehahthahaiohh</div>
kzhao14
  • 2,470
  • 14
  • 21
0

You can use TextArea not input tag.

and textarea will do the needful by default. also there is one option for multiline like setting attribute rows.

and then you will not need to set height.

check fiddle here.

https://jsfiddle.net/yxbpoh2d/

<textarea name="message" id="contact_message"></textarea>
#contact_message {
    width: 400px;
    height:400px;
}
pathak tejpal
  • 838
  • 1
  • 7
  • 13
0

There are various options that you can use.Check here

Here is a fiddle.

 textarea {
    height: 400px;
    width: 400px;
}

Hope it helps.

Community
  • 1
  • 1
shubham agrawal
  • 3,435
  • 6
  • 20
  • 31
0

#contact_message {
    width: 400px;
    height:400px;
}
<textarea id="contact_message" rows="4" cols="50">

</textarea>