如何展开文本区域以填充页面
How to expand textarea to fill up page
我有一个非常简单的html页面,上面有一个顶部栏和一个文本区域。我希望文本区域填充顶部栏留下的高度。调整大小后需要自动调整。
例如
<html>
<body>
<div id="top" />
<textarea id="text" />
</body>
</html>
我试过很多东西,但最后总是有两个滚动条(一个用于文本区域,一个用于正文)。
如果你有一个固定高度的顶部栏,你可以使用文本区域上的绝对位置来填充剩下的区域,如下所示:
body {
margin: 0;
}
#top {
color: #ffffff;
background: #333399;
height: 50px;
padding: 10px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#text {
position: absolute;
top: 50px;
bottom: 0;
left: 0;
right: 0;
width: 100%;
padding: 10px;
margin: 0;
resize: none;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
<div id="top">Top</div>
<textarea id="text">Textarea</textarea>
如果我理解正确,也许这可以帮助jsfiddle,但我不确定这是否是你想要的,这只是我认为你可能会问的原始版本。还要注意,如果您已经重置了css ,那么可以避免一些声明
HTML
<div class="content">
<div id="top"></div>
<textarea id="text"></textarea>
</div>
CSS
body,html{
height:100%;
padding:0;
margin:0;
}
.content{
position:relative;
height:100%;
}
#top{
height:50px;
background-color:#CCC;
width:100%;
}
#text{
height:85%;
border:0;
padding:0;
margin:0;
background-color:#999;
}
检查此代码
JS:
totalCalc();
function totalCalc()
{
var bodyHeight = $("body").outerHeight(true);
var topHeight = $("#top").outerHeight(true);
var txtareaHeight = bodyHeight - topHeight - 10;
$('#text').attr("style", "height:" + txtareaHeight + "px");
}
$(window).resize(totalCalc);
CSS:
*{margin:0; padding:0; font-family:Tahoma; font-size:12px; color:#333;}
html, body{height:100%; overflow:hidden;}
#top{padding:10px;}
#text{margin:0 10px;}
Fiddle
相关文章:
- 使用JSON文件中的变量(字符串)填充文本区域
- 部分填充区域的折线图
- 提交表单时,Javascript(JQuery)不会在文本区域中填充内容
- PHP:Can't填充TinyMCE文本区域
- '使用文本区域中的字符串动态填充下拉菜单
- 有没有一种方法可以用包含ENTER键换行符的SQL数据填充文本区域表单
- 文本区域在IE 10中填充了[object HTMLMetaElement]
- 将文本区域的值添加到已填充的输入中
- 使用php创建的下拉列表中的选择单独填充文本区域
- 使用JavaScript返回click-li项目的值,并用结果填充文本区域
- 在模式窗口中填充文本区域
- 如何通过选择从SQL填充的下拉列表来检索SQL中的值到文本区域使用JavaScript在PHP中
- 尝试制作可重用的代码,使用函数参数填充名为 target 的变量的区域
- 如何在高图表的 2 点之间制作颜色填充区域
- 如何在莫里斯.js中更改填充区域的颜色
- Javascript-Photoshop脚本-将所有填充区域提取到新层中
- Highcharts未跟踪填充区域下的鼠标活动
- Html5 canvas 2d制作人体和填充区域
- 带有填充区域图的工具提示
- JS画布-如何用位图填充区域