views:

63

answers:

1

How can i prevent the textarea from stretching beyond his parent DIV elemnt?

I have this textarea inside a table that it is inside a DIV and it seems that it cause the entire table to streach out of it's bounds.

You can see an example of the same situation even in a more simple case, just putting a text area inside a div (like what is used here in www.stackoverflow.com)

You can see from the images below that the textarea can stretch beyond the size of it's parent? how do i prevent it?

I'm kind of new to CSS so i don't really know what CSS attributes should i be using...i tried several like Display, and Overflow. But they don't seem to make the trick. Anything else i have might of missed?

the div section

the text area

UPDATE: HTML

CSS

textarea { max-width: 50%; }

container {

width: 80%;
border: 1px solid red;

}

cont2{

width: 60%;
border: 1px solid blue;

} ​

if you put this code inside the http://jsfiddle.net you will see that they act differently, although the textarea is limited to the percentage declared in his css style, it is still possible to get him to cause his table parent to be as large as it wants to be, and then you can see that it goes out of the parent border. Any thoughts on how to fix this? ​

+2  A: 

In case i understood you correctly...:

textarea {
    resize: none;
}

Or you can limit size:

textarea {
    max-width: 100px; 
    max-height: 100px;
}
Māris Kiseļovs
can i still keep the manual stretching available just limit the stretching stays in the bound of it's parent element?
Itay Levin
Is that a CSS attribute? it's not valid in css 2.1
Itay Levin
Yes, it's CSS attribute but it will not validate. I also updated my answer.
Māris Kiseļovs
i have tried the resize, it worked.
Itay Levin
i wonder i f i could make it work also with the width as a precentage and not a fixed number of pixels. because i want to allow the user to resize the text area but not break down the screen structure.
Itay Levin
Setting max-width as percentage works well - http://jsfiddle.net/paGE3/ . By the way, please accept my answer if it's working.
Māris Kiseļovs
10x Māris. Its looks the same as my code...i don't understand why my original code didn't work. i will check again.
Itay Levin
Can you take a look at the update i have written?
Itay Levin
@Māris Kiseļovs - setting max-width doesn't work on Tables.
Itay Levin
@Itay Levin - try to define cell's and tables width. And this is another question now...
Māris Kiseļovs