Sac*_*cha 2 html css scrollbar contenteditable
我有一个div
与contenteditable
标签设置为true
。
此外,我已经添加了width
,height
等使用CSS。
然后这是结果:
#stringinput {
min-width: 20em;
min-height: 1.4em;
max-width: 40em;
max-height: 10em;
padding: 0.3em 0.5em 0 0.5em;
background-color: white;
font-size: larger;
text-align: left;
border: 3px solid black;
border-radius: 5px;
}
Run Code Online (Sandbox Code Playgroud)
<div contenteditable="true" id="stringinput" spellcheck="false"></div>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是当您输入并达到max-height
限制时,div 向下扩展,但边框保持在应有的位置。
所以,我希望当有人达到max-height
限制时出现一个滚动条,这样 div 就不会进一步向下扩展。我该怎么做?
overflow-y: auto;
像这样插入:
#stringinput {
overflow-y: auto;
//More code
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
#stringinput {
overflow-y: auto;
//More code
}
Run Code Online (Sandbox Code Playgroud)
#stringinput {
min-width: 20em;
min-height: 1.4em;
max-width: 40em;
max-height: 10em;
padding: 0.3em 0.5em 0 0.5em;
background-color: white;
font-size: larger;
text-align: left;
border: 3px solid black;
border-radius: 5px;
overflow-y: auto;
}
Run Code Online (Sandbox Code Playgroud)
overflow-y: auto
当达到max-height
(y 轴)限制时,该属性会自动启用滚动条。