如何强制一个内容可编辑的 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-x
和 overflow-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/