Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Setting Textarea width to 100%

Tags:

html

css

I have a Textarea inside a TD tag and I want to set the textarea width to 100% so the width is the same as the TD width.

I've used:

textarea{width:100%}

But it didn't work.

Anyone have any ideas why it's not working please?

Thanks

like image 702
Satch3000 Avatar asked Apr 15 '11 22:04

Satch3000


People also ask

How do I make a text area 100?

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%. HTML Code: The HTML code contains a <textarea> element that holds rows and columns values.

How do I change the width of a text area in CSS?

In CSS, you need to use the width and height properties for the <textarea> element.

What does width 100% do in CSS?

It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.

How do I limit textarea size?

In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.


1 Answers

The problem is, as far as I can think of: that your textarea wants to get its width (100%) from the td it is in. But a td has a dynamic width by default, so unless you don't specify the width of your td, you won't get your textarea to be 100% of your cell.

A cell has no width by itself, even though you would think it will autoscale with your table. Well, it doesn't, because this auto scaling is determined by the content inside it. So content of 100% is not interpreted correct, because the 100% depends on the width of the td which is dynamic by itself.

And I can continue looping with this answer like this...

like image 144
Marnix Avatar answered Sep 27 '22 01:09

Marnix