Html 文本区域最大宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27939344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:21:04  来源:igfitidea点击:

Textarea max-width

htmlcsstextarea

提问by no1lov3sme

I'm having problem with textarea max-width, I need it to not exceed .table-cell.twowidth when resized, on this example:

我遇到了 textarea max-width 的问题,我需要它在调整大小时不超过.table-cell.two宽度,在这个例子中:

JSfiddle example

JSfiddle 示例

HTML:

HTML:

<div class="wrapper">
<div class="table">
    <div class="table-cell one">
        <p>small cell</p>
    </div>
    <div class="table-cell two">
        <p>textarea cell</p>
        <textarea></textarea>
    </div>
</div>

CSS:

CSS:

textarea {
  max-width: 100%;
}

.wrapper {
  width: 500px;
}

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

.table-cell {
  display: table-cell;
  background: #E2D8C1;
  vertical-align: top;
  padding: 10px;
}

.table-cell.two {
  width: 100%;
  background: #DAC082;
}

.table textarea {
  max-width: 100%;
  width: 100%;
  height: 100px
}

Please do not advise using javascript, needed a pure css solution.

请不要建议使用 javascript,需要一个纯 css 解决方案。

回答by Bhojendra Rauniyar

Use:

用:

textarea { 
   /* will prevent resizing horizontally */
   resize:vertical;
}

回答by user6297197

I have this problem too. The solution is very simple but i spend few hours for experiments... Use this two parameters at the same timein textarea element class/#element style definition (90% 30% are example values) :

我也有这个问题。解决方案非常简单,但我花了几个小时进行实验...在 textarea 元素类/#element 样式定义中同时使用这两个参数(90% 30% 是示例值):

.textarea {
    width:90%;
    max-width:90%;
    max-height:30%;
}

回答by Naveen - ?????

For default the text area is re sizable. If you want to increase the element width, you can do it by

默认情况下,文本区域可调整大小。如果你想增加元素宽度,你可以通过

HTML

HTML

<textarea rows="4" cols="50">Content here</textarea>

CSS

CSS

max-width: 300px;
max-height:300px

Demo on jsfiddle

jsfiddle 上的演示

In your case you want to fix the <textarea>size when the parent does not have a fixed size.

在您的情况下,您希望<textarea>在父级没有固定尺寸时固定尺寸。

回答by AVM

For textarea you can set

对于 textarea,您可以设置

<textarea rows="5"></textarea>

and in css

并在 css 中

textarea { height: auto; }