最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

resize textarea to fit in a fluid width layout with javascript - Stack Overflow

programmeradmin3浏览0评论

I have a fluid layout and i need a textarea to expand/reduce depending of the size of the parent container.

In CSS it would look like this:

textarea{
width: 100%;
}

But this doesn´t work with textareas.

How can I do this with javascript? I can get the parent element width and them calculate the number of cols to fit that width but how do I know the size of 1 col (in px)?

I have a fluid layout and i need a textarea to expand/reduce depending of the size of the parent container.

In CSS it would look like this:

textarea{
width: 100%;
}

But this doesn´t work with textareas.

How can I do this with javascript? I can get the parent element width and them calculate the number of cols to fit that width but how do I know the size of 1 col (in px)?

Share Improve this question asked Oct 7, 2010 at 11:12 brpazbrpaz 3,6589 gold badges49 silver badges77 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

chk this out : http://css-tricks./box-sizing/

  textarea {
            -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
            -moz-box-sizing: border-box;    /* Firefox, other Gecko */
             box-sizing: border-box;         /* Opera/IE 8+ */
           }

It's 2014, and width: 100%; now works with textareas in current versions of Chrome, Firefox, IE, Opera, and Safari.

发布评论

评论列表(0)

  1. 暂无评论