[英]Set max-width for textarea within fieldset
I want to restrict the stretching of a textarea to 100% of the parent fieldset.我想将文本区域的拉伸限制为父字段集的 100%。
According to this question it works, when the parent is a div: How can I prevent the textarea from stretching beyond his parent DIV element?根据这个问题,当父级是 div 时,它起作用: 如何防止 textarea 超出其父级 DIV 元素? (google-chrome issue only)
(仅限谷歌浏览器问题)
Now with fieldsets this doesn't seem to work: http://jsfiddle.net/b4oLy135/7/现在使用字段集,这似乎不起作用: http ://jsfiddle.net/b4oLy135/7/
HTML HTML
<fieldset id="container">
<textarea></textarea>
</fieldset>
CSS CSS
textarea {
max-width: 50%;
}
#container {
max-width: 80%;
border: 1px solid red;
}
What am I missing here?我在这里想念什么?
You can do the following.您可以执行以下操作。
#container { position: relative; max-width: 80%; overflow: none; border: 1px solid red; height: 100px; margin: 0; padding: 5px; } textarea { position: absolute; display: block; width: 40%; max-width: calc(100% - 15px); height: 40%; max-height: calc(100% - 15px); }
<fieldset id="container"> <textarea></textarea> </fieldset>
This way the textarea
can only be resized to the width & height of its parent fieldset
.这样
textarea
只能调整为其父fieldset
的宽度和高度。
If you have more then one <input>
in your fieldset, absolute positioning does not work.如果您的字段集中有多个
<input>
,则绝对定位不起作用。
My solution was to just use a wrapper over every <textarea>
field, so I could use the solution I referred to in t the question .我的解决方案是在每个
<textarea>
字段上使用一个包装器,这样我就可以使用我在问题中提到的解决方案。
Important:重要的:
Does not work when using There is a bug when using %
on the parent.在父级上使用
%
时不起作用。%
and stretching over 200% of the parent.使用
%
并拉伸超过 200% 的父级时存在错误。
Here is my current fiddle: https://jsfiddle.net/d23hgb8w/3/这是我目前的小提琴: https://jsfiddle.net/d23hgb8w/3/
HTML HTML
<fieldset>
<div class="textarea__wrapper">
<textarea></textarea>
</div>
<input>
</fieldset>
CSS CSS
.textarea__wrapper {
border: 1px solid red;
width: 500px;
}
textarea {
max-width: 100%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.