You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

网站文本框高度改后回弹无法固定为80px 求助对应class

文本框固定80px高度实现方案

你遇到的点击后高度回弹问题,本质是原有站点的CSS交互态样式、或自动调整输入框高度的JS脚本覆盖了你手动修改的高度参数,按以下步骤操作即可生效:

  • 先定位文本框对应的选择器:普通单行输入框用input[type="text"]匹配,多行输入框用textarea匹配,富文本编辑区找带contenteditable="true"属性的容器,常见类名包含form-control、text-input、editor-content,直接在浏览器开发者工具里选中元素就能拿到它的实际class类名。
  • 给目标类追加以下CSS规则,必须同时锁定最大、最小高度,且覆盖聚焦激活状态的样式,避免回弹:
/* 将.textarea-box替换为你实际获取到的文本框类名 */
.textarea-box {
  height: 80px !important;
  min-height: 80px !important;
  max-height: 80px !important;
  resize: none !important;
  overflow-y: auto !important;
}
/* 覆盖点击聚焦时的默认样式,这一步是解决回弹的核心 */
.textarea-box:focus,
.textarea-box:active {
  height: 80px !important;
  min-height: 80px !important;
  max-height: 80px !important;
}
  • 如果加完CSS仍然回弹,说明存在JS动态给元素写入内联高度样式,直接给文本框标签加内联样式兜底即可:
<textarea style="height: 80px !important; min-height: 80px !important; max-height: 80px !important; resize: none;"></textarea>

不要只单独设置height属性:绝大多数框架的输入框默认会给min-height设置更高的固定值,只改height会被min-height规则撑大,必须三个高度属性同时锁定,配合!important提权就能覆盖所有原有样式。

内容的提问来源于stack exchange,提问作者Chad Davis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.02 23:48:37