gpt4 book ai didi

html - 当文本区域位于网格容器中时如何使 cols =""工作

转载 作者:太空狗 更新时间:2023-10-29 12:39:07 27 4
gpt4 key购买 nike

textarea 元素位于网格容器中时,Chrome 和 Firefox 似乎都不遵守 cols 属性:

.grid { display: grid; }

textarea:not([cols]) { width: 100%; }
<h2>Not in a grid container:</h2>

<div>
<textarea cols="10" rows="6">some dummy text</textarea>
<textarea>some other text</textarea>
</div>

<h2>In a grid container:</h2>

<div class="grid">
<textarea cols="10" rows="6">some dummy text</textarea>
<textarea>some other text</textarea>
</div>

正如我所料,rows 属性得到了尊重。

我需要一个 texarea,当 网格容器内时,如果 cols 不存在,则尊重 cols , 占可用宽度的 100%。

最佳答案

你需要一个 block 元素父元素来修复它。

.grid {
display: grid;
}

textarea:not([cols]) {
width: 100%;
}
<h2>Not in a grid container:</h2>

<div>
<textarea cols="10" rows="6">some dummy text</textarea>
<textarea>some other text</textarea>
</div>

<h2>In a grid container:</h2>

<div class="grid">
<div>
<textarea cols="10" rows="10">some dummy text</textarea>
</div>
<textarea>some other text</textarea>
</div>

关于html - 当文本区域位于网格容器中时如何使 cols =""工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58006126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com