This topic created in 5699 days ago, the information mentioned may be changed or developed.
<style>
div{
width:90%;
background:#f00;
}
textarea{
width:100%;
padding:20px;
}
</style>
<div><textarea></textarea></div>
代码如上。
textarea 的宽度大约会溢出外边 div 的 20px*2 = 40px。
这个如何解决呢?
11 replies • 1970-01-01 08:00:00 +08:00
 |
|
1
no2x Oct 20, 2010
直接解决的办法不会。
小聪明的办法一个:Div 的 Css 里加上一个 padding:0 40px 0 0;
|
 |
|
2
darcy Oct 20, 2010
<style type="text/css"> textarea { width:100%; } .textwrapper { border:1px solid #999999; margin:5px 0; padding:30px; } .container{ width:90%; } </style> <div class="container"> <div class="textwrapper"><textarea cols="2" rows="10" id="rules"/></div> </div>
|
 |
|
4
chone Oct 20, 2010
lz的意思是需要让textarea和容器边界有20px的间隙, 还是需要让容器的宽度只有90%?
|
 |
|
5
POPOEVER Oct 20, 2010 via iPad
padding 是不计入盒模型宽度的
|
 |
|
6
POPOEVER Oct 20, 2010 via iPad
估摸着你要的效果应该用 div {width:100%} textarea {margin:0 20px} 来解决
|
 |
|
7
AJ Oct 20, 2010
不要用width:100%,任何容器加上此再加padding都会溢出
|
 |
|
8
AJ Oct 20, 2010
|
 |
|
9
qifei Oct 20, 2010
行李员真是诲人不倦啊
|
 |
|
10
darasion Oct 20, 2010
我最终决定,放弃padding了。
|