conteneditable div上的光标不是占位符的开始,而在chrome和firefox中可以正常工作。
div是自动聚焦的,并且光标必须从头开始显示。
<div id="" class="chatInput" contenteditable="true" placeholder="Type something..." autofocus="autofocus"></div>
.cInput{
padding: 5px 15px;
color: var(--text-base-volumeone);
outline: none;
cursor: text;
max-height: 32px;
overflow-x: hidden;
overflow-y: auto;
width: 100%;
min-height: 32px;
font-family: LATORegular;
font-size: 13px;
vertical-align: bottom;
transition: border-color 0.25s ease;
caret-color: var(--caret-color);
position: relative;
white-space: initial;
}
我尝试搜索该问题,它看起来像是MS Edge旧版浏览器中的已知问题。
这里是您可以尝试使用MS Edge旧版浏览器的一种解决方法。
<!DOCTYPE html>
<html>
<head>
<style>
[contenteditable=true] {
position: relative;
}
[contenteditable=true]:empty:before {
content: attr(placeholder);
position: absolute;
left: 0;
right: 0;
top: 4px;
margin: auto;
}
#myDiv {
border: 1px dashed #AAA;
width: 290px;
padding: 5px;
text-align: left;
height: 16px;
}
</style>
</head>
<body>
<div id="myDiv" contenteditable="true" placeholder="Enter text here..."></div>
</body>
</html>
MS Edge旧版浏览器中的输出:
此解决方案使用CSS代码。我们可以注意到,光标在div外几乎没有显示。如果这不是最好的选择,那么您可能需要使用JavaScript或Jquery在开始位置显示光标。
This example使用JQuery。