强制内容可编辑div上的维度?

时间:2014-10-19 22:26:37

标签: javascript jquery html css

如何强制内容可编辑div的行为类似于文本框?也就是说,它有一个固定的水平宽度,但无限扩展?这是一个jsfiddle,下面是小提琴代码的副本: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>

1 个答案:

答案 0 :(得分:1)

使用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>