javascript - 在内容可编辑的 div 上强制尺寸?

标签 javascript jquery html css

如何强制一个内容可编辑的 div 表现得像一个文本框?也就是说,它具有固定的水平宽度但垂直无限扩展?这是一个 jsfiddle,下面是 fiddle 中代码的副本:http://jsfiddle.net/seoj7cgq/

<!--How do I force the text to stay in the div horizontally and scroll infinitely vertically?-->
<title>JS Bin</title>
<style>

  .element {
    max-height: 200px;
    width:300px;
    height:300px;
    max-width: 300px;
    background: #999;
    overflow: hidden;
}

</style>
</head>
<body>
  <div class="element" contenteditable=true>
    this is the text
  </div>
</body>
</html>

最佳答案

使用 overflow-xoverflow-y属性:

.element {
  max-height: 200px;
  width: 300px;
  height: 300px;
  max-width: 300px;
  background: #999;
  overflow-x: hidden;
  overflow-y: scroll;
}
<div class="element" contenteditable=true>this is the text</div>

关于javascript - 在内容可编辑的 div 上强制尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26456087/

相关文章:

javascript - 创建从一个对象到另一个对象的动态线 Three.js

javascript - 为什么 fillRect 命令不允许创建命中区域,而 rect 和 fill 的组合却可以?

javascript - 当值已被选择时,JS on Change 不适用

php - 我的 CSS 文件在我的 PHP 文件中不起作用

Javascript 检查文本区域是否已设置

javascript - 如何通过 jquery 或 javascript 将多选下拉值插入到 var 中?

javascript - 动态加载JWplayer

javascript - jquery mobile 移动返回过渡?

html - ul 没有得到正确的高度

css - 如何隐藏 div 的溢出?