Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move to new line when input field width exceeds

I'm trying to move excess text to a new line when there's no more space in the first line. But my text just keep on filling in the same line without moving to another line. How can i fix this? I want to move to the next line when text is filled in the first line.

I already tried

word-wrap: break-word

white-space: initial;

But to no effect.

My code is like below:

<form onSubmit={ handleSubmit }>
   <div className="create_post_div unchange_div">
        <Field
            name="askQuestionInput"
            component="input"
            type="text"
            className="post_input_preview unchange_div"
            placeholder="Ask your question here"
        />
    </div>
</form>

My css classes:

.create_post_div{

    width: 100%;
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 10px;
}

.post_input_preview {

    width: 640px;
    border: none;
    margin-bottom: 10px;
    font-size: 16px;
    outline: none;
}

Thanks in advance.

like image 1000
CraZyDroiD Avatar asked Aug 09 '17 06:08

CraZyDroiD


People also ask

How do you Enter a new line in input?

By default, pressing Enter or Shift and Enter will generate a new line for a textarea element.

How do I move text to a new line?

Thankfully, there is a keyboard shortcut that moves to the next line. Move the text cursor to where you want the new line to begin, press the Enter key, hold down the Shift key, and then press Enter again.

How do you go to the next line in a text box in HTML?

<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.


1 Answers

HTML input elements won't wrap in the way that you're describing. See here.

You can however change your input type=['text'] to a textarea, and as a user types, the text will wrap onto the next line. See this answer.

like image 145
aidan Avatar answered Sep 21 '22 12:09

aidan