You need to enable JavaScript to run this app. 如何调整设置contenteditable属性的可编辑文本框的尺寸
优惠活动
大模型
产品
解决方案
定价
更多

如何调整设置contenteditable属性的可编辑文本框的尺寸

问题原因
  • CSS语法错误:editor.css中font-family: "Montserrat"行末尾缺失分号,会导致后续高度相关属性无法被浏览器正常解析。
  • 百分比高度无效:你给.editor设置的height: 200%为相对高度,需要父元素body、html存在明确的高度定义才能生效,当前父元素无高度配置,所以该属性不会起作用。
  • 布局属性适配问题:display: inline-block更适合行内块级元素场景,作为全宽编辑器容器使用块级布局更合理。
修复方案

你可以根据需求选择固定高度或者自适应高度两种方案:

方案1:设置固定高度(最简单)

直接修改editor.css即可,调整后的代码如下:

//this is editor.css
.editor{
  background-color: #1d1f21;
  color: #c5c8c6;
  font-family: "Montserrat";
  font-weight: 100;
  width: 100%;
  height: 600px; /* 按需调整数值即可控制编辑器高度 */
  display: block;
  overflow: auto; /* 内容超出时自动出现滚动条,更适配编辑器场景 */
}

::selection{
  background: #373b41;
}

方案2:自适应占满视口剩余高度

如果需要编辑器自动占满浏览器窗口剩下的空间,需要同步修改page.css:
首先修改page.css:

//this is page.css
html, body {
  height: 100%;
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
}
.main{
  background-color: #282a2e;
  color: #969896;
  font-family: "Raleway", "Montserrat";
  font-weight: 100;
  display: flex;
  flex-direction: column;
  height: 100%;
}

然后修改editor.css:

//this is editor.css
.editor{
  background-color: #1d1f21;
  color: #c5c8c6;
  font-family: "Montserrat";
  font-weight: 100;
  flex: 1; /* 占满父容器剩余高度 */
  width: 100%;
  display: block;
  overflow: auto;
}

::selection{
  background: #373b41;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 23:18:00