html - 样式化空文本区域高度

标签 html css input textarea

我正在尝试将 textarea 放入我的布局中。但是,当它只有占位符为空时,似乎添加了一个额外的行。我希望摆脱它,因为它破坏了我的布局。我无法设置固定高度,因为文本区域根据文本输入是可变的。

这是截图。 enter image description here

这里是 Safari 中显示的所有规则(我省略了那些不活动的)。

CSS:

min-height: 36px;
padding: 16px;
margin-right: 16px;
box-sizing: border-box;
font-size: 14px;
max-height: 100px;
overflow: hidden;
resize: none;
width: 80%
-webkit-appearance: textarea;
background-color: white;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: initial;
border-right-color: initial;
border-bottom-color: initial;
border-left-color: initial;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
-webkit-rtl-ordering: logical;
-webkit-user-select: text;
flex-direction: column;
cursor: auto;
white-space: pre-wrap;
word-wrap: break-word;
margin-top: 0em;
margin-bottom: 0em;
margin-left: 0em;
font-style: normal;
font-weight: 400;
font-family: -apple-system;
font-variant: normal;
color: initial;
letter-spacing: normal;
word-spacing: normal;
line-height: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
-webkit-writing-mode: horizontal-tb !important;
list-style: none;

感谢您的帮助!

编辑:这是没有应用最小高度和填充的相同元素。 enter image description here

最佳答案

大多数浏览器将文本区域的默认行设置为 2 行,您可以在此处看到:https://www.w3.org/wiki/HTML/Elements/textarea .

没有 css 属性可以修改文本区域中的行数。

如果您真的需要 1 行,您可以设置 rows='1',然后使用 javascript 在用户输入时动态添加更多行。你可以在这里找到一个例子:add new row to textarea input while editing

关于html - 样式化空文本区域高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34875710/

相关文章:

java - 如何创建 HTML 文件表格以供下载?

javascript - 屏幕高度滑动菜单和内容

html - 响应式 2 列不在顶部排列

javascript - Jquery - 使用 $(this) 获取文本输入的值

javascript - 如何仅模糊背景而不模糊 Ionic/CSS 中的内容

css - 调整 WordPress 标题中的图标大小

javascript - 检测使用 javascript 动态分配的 css 样式/属性

javascript - <链接> 为 "react-router-dom 6.7.0"

css - 在输入数字中隐藏向上和向下箭头按钮(微调器)- Firefox 29

c - 输入到无符号字符数组