在div上使用contenteditable属性并插入跨度的html元素时,由于某种原因,插入符号会在跨度旁边更改位置。
因此您可以看到插入符号已被向上推:
什么是控制插入符号位置的信息,我必须用什么机制对其进行更改?
html:
<div style="resize:none; overflow: auto; border: none" contenteditable="true">
is your email still <span class="inline-button" contenteditable="false">Email</span>?
</div>
css:
.inline-button {
background-color: green;
border: none;
color: black;
padding: 4px 4px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
pointer-events: none;
font-weight: bold;
font-size:0.8em;
}
.inline-button {
background-color: green;
border: none;
color: black;
padding: 4px 4px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
pointer-events: none;
font-weight: bold;
font-size:0.8em;
}
<div style="resize:none; overflow: auto; border: none" contenteditable="true">
is your email still <span class="inline-button" contenteditable="false">Email</span>?
</div>
答案 0 :(得分:2)
这是因为span
上的填充。
.inline-button {
background-color: green;
border: none;
color: black;
padding: 0px 4px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
pointer-events: none;
font-weight: bold;
font-size:0.8em;
}
<div style="resize:none; overflow: auto; border: none" contenteditable="true">
is your email still <span class="inline-button" contenteditable="false">Email</span>?
</div>