我無法獲得一個contentEditable元素來顯示爲一個固定的框(例如2個字符寬)。因爲它只是填充的寬度。在框中有文本時工作正常,但我希望有一個具有特定寬度的空框。有任何想法嗎?如何設置html內容固定寬度的可編輯div
HTML:
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="so.css" />
<body>
<h1 id="prompt">Type something in the box:</h1>
<h1 id="textarea"></h1>
</body>
CSS:
#prompt, #textarea{
display:inline;
}
#textarea{
contentEditable: true;
width: 2em; /* 20px doesn't work either */
cursor: text;
background-color:rgba(132, 225, 132, 0.9);
border: 1px solid black;
padding: 2px;
}
,評估您的H1,使用任何顯示,但內聯,或浮起來。位置:固定/絕對將允許您調整它的大小。只有**內聯不會允許**它:) –