79

如何将文本区域宽度扩展到父级的 100%?

我尝试宽度为 100%,但它不起作用,它扩展到页面的 100%,什么崩溃布局。

这里是视觉方式的问题。 在此处输入图像描述

请提供一些提示。

4

7 回答 7

85

<div>
  <div style="width: 20%; float: left;">
    <p>Some Contentsssssssssss</p>
  </div>
  <div style="float: left; width: 80%;">
    <textarea style="width: 100%; max-width: 100%;"></textarea>
  </div>
  <div style="clear: both;"></div>
</div>

 

于 2013-06-20T09:43:52.987 回答
11

您需要定义width包含 的 div ,textarea并且当您声明时textarea,您可以设置.main > textarea为 have width: inherit

注意:.main > textarea表示带有<textarea>的元素的内部class="main"

这是工作解决方案

的HTML:

<div class="wrapper">
  <div class="left">left</div>
  <div class="main">
    <textarea name="" cols="" rows=""></textarea>
  </div>
</div>

CSS:

.wrapper {
  display: table;
  width: 100%;
}

.left {
  width: 20%;
  background: #cccccc;
  display: table-cell;
}

.main {
  width: 80%;
  background: gray;
  display: inline;
}

.main > textarea {
  width: inherit;
}
于 2013-06-20T09:28:27.287 回答
11

盒子模型是每个 Web 开发人员都应该知道的。使用百分比作为填充/边距的大小和像素是行不通的。总有一个分辨率看起来不太好(例如,在宽度低于 100 像素的 div 中给出 90% 的宽度和 10 像素的填充/边距)。

检查一下(使用 micro.pravi 的代码):http: //jsbin.com/umeduh/2

<div id="container">
    <div class="left">
        <div class="content">
            left
        </div>
    </div>
    <div class="right">
        <div class="content">
            right
            <textarea>Check me out!</textarea>
        </div>
    </div>
</div>

<div class="content">那里,您可以使用填充和边距而不会搞砸浮动。

这是 CSS 中最重要的部分:

textarea {
    display: block;
    width: 100%;
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;
}
于 2013-06-20T09:39:03.217 回答
2

HTML:

<div id="left"></div>
<div id="content">
        <textarea cols="2" rows="10" id="rules"></textarea>
</div>

CSS:

body{
    width:100%;
    border:1px solid black;
    border-radius:5px;

}
#left{
    width:20%;
height:400px;
    float:left;
    border: 1px solid black;
    display:block;
}
#content{
    width:78%;
    height:400px;
    float:left;
    border:1px solid black;
    text-align:center;
}
textarea
{
   margin-top:100px;
    width:98%;
}

演示: 这里

于 2013-06-20T09:34:44.963 回答
1

我会做这样的事情:

HTML:

<div class="wrapper">
    <div class="side">sidebar here</div>
    <div class="main">
        <textarea class="taclass"></textarea>
    </div>
</div><!--/ wrapper -->

CSS:

.wrapper{
    display: block;
    width: 100%;
    overflow: hidden;
}
.side{
    float:left;
    width:20%;
}
.main{
    float:right;
    width:80%;
}
.taclass{
    display:block;
    width:100%;
    padding:2%;
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;
}
于 2013-06-20T09:25:05.050 回答
0

试试这个..在你的页面中添加这个

<style>
textarea
{
width:100%;
}
</style>
于 2013-06-20T09:23:42.513 回答
0

添加CSS

  <style type="text/css">
    textarea
    {

        border:1px solid #999999
        width:99%;
        margin:5px 0;
        padding:1%;
    }
</style>
于 2013-06-20T09:24:51.460 回答