Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand textarea width to 100% of parent (or how to expand any HTML element to 100% of parent width)?

Tags:

html

css

How to expand textarea width to 100% of parent?

I try width 100% but it is not works it expands to 100% of page what crash layout.

Here the question in visual way. enter image description here

Please provide some hints.

like image 373
Chameleon Avatar asked Jun 20 '13 09:06

Chameleon


People also ask

How do I make 100 area text width?

The idea is to create a div with the class name “wrapper”. Inside that <div> element, we create a text area with a certain number of columns and rows. In this case, it is 30 and 15 respectively. After that, we set the width property to 100% to make a textarea width 100%.

How do I increase the width of a textarea in HTML?

You need to define width of the div containing the textarea and when you declare textarea , you can then set . main > textarea to have width: inherit . Note: .

How do I change the width of a textarea?

There are two ways of setting the size of the HTML <textarea> element. You can use HTML or CSS. In HTML, you can use the cols and rows attributes.


2 Answers

<div>    <div style="width: 20%; float: left;">      <p>Some Contentsssssssssss</p>    </div>    <div style="float: left; width: 80%;">      <textarea style="width: 100%; max-width: 100%;"></textarea>    </div>    <div style="clear: both;"></div>  </div>     
like image 161
Gangadhar Avatar answered Sep 17 '22 18:09

Gangadhar


The box model is something every web-developer should know about. working with percents for sizes and pixels for padding/margin just doesn't work. There always is a resolution at which it doesn't look good (e.g. giving a width of 90% and a padding/margin of 10px in a div with a width of under 100px).

Check this out (using micro.pravi's code): http://jsbin.com/umeduh/2

<div id="container">     <div class="left">         <div class="content">             left         </div>     </div>     <div class="right">         <div class="content">             right             <textarea>Check me out!</textarea>         </div>     </div> </div> 

The <div class="content"> are there so you can use padding and margin without screwing up the floats.

this is the most important part of the CSS:

textarea {     display: block;     width: 100%;     -webkit-box-sizing: border-box;        -moz-box-sizing: border-box;             box-sizing: border-box; } 
like image 25
Broxzier Avatar answered Sep 20 '22 18:09

Broxzier