Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

html - Textarea height: 100%

Here's my fiddle: http://jsfiddle.net/e6kCH/15/

It may sound stupid, but I can't find a way to make the text area height equal to 100%. It works for the width, but not for height.

I want the text area to resize depending of the window size...like it works in my fiddle for the width...

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Height of an element is relative to its parent. Thus, if you want to make expand your element into the whole height of the viewport, you need to apply your CSS to html and body as well (the parent elements):

html, body {
    height: 100%;
}

#textbox {
    width: 100%;
    height: 100%;
}

Alternative solution with CSS3: If you can use CSS3, you can use Viewport percentage units and directly scale your textbox to 100 % height (and 100% width) of the viewport (jsfiddle here)

body {
    margin: 0;
}
#textbox {
    width: 100vw;
    height: 100vh;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...