如何强制内容可编辑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>
答案 0 :(得分:1)
使用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>