Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add newline to textarea after label

Tags:

html

css

I'm trying to get the following pattern which is from Microsoft Word:

enter image description here

and in HTML I'm getting:

enter image description here

How do i code it in the way where the textarea is after the label like the visualization in word above?

<!DOCTYPE html>
<html lang = "en">
<head>
    <meta charset = "UTF-8">
    <title>testform</title>
    <link rel = "stylesheet" href = "test2.css">
</head>

<body>
    <div class = "entity">
        <label >Enter your address</label>
        <textarea id = "addr_out"></textarea>
    </div>
</body>
like image 425
Maxxx Avatar asked Mar 02 '23 23:03

Maxxx


2 Answers

This can be done in a couple of ways:

(old hack) would be adding <br> after the label but I don't recommend this:

<label >Enter your address</label><br/>

Or you can also make it so the label and the textarea is wrapped on a different div considering that div is full width:

<div class = "entity">
   <label >Enter your address</label>
</div>
<div class = "entity">
   <textarea id = "addr_out"></textarea>
</div>

OR you can do it on css, either make the label width 100%:

textarea {
  width: 100%;
}

OR make the .entity use flex:

.entity {
  display: flex;
}
like image 187
I am L Avatar answered Mar 05 '23 17:03

I am L


Just add display: block.

#addr_out {
  border: 2px solid green;
  width: 200px;
  height: 100px;
  display: block;
  resize: none;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>testform</title>
  <link rel="stylesheet" href="test2.css">
</head>

<body>
  <div class="entity">
    <label>Enter your address</label>
    <textarea id="addr_out"></textarea>
  </div>
</body>
like image 34
barhatsor Avatar answered Mar 05 '23 16:03

barhatsor