为什么插入符号在可满足的With位置不可见:Relative?

原学程将引见为何拔出标记在可知足的With地位弗成睹:Relative?的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

为什么插入符号在可满足的With位置不可见:Relative? 教程 第1张

成绩描写

contenteditable元素具备position: relative以及配景色时,拔出标记搁在该元素中时是弗成睹的。上面是1个例子:

数据-lang="js"数据-隐蔽="假"数据-掌握台="真"数据-巴贝我="假">

.bug {
  position: relative;
  background-color: lightgrey;
}
<div contenteditable>
  This has caret
  <span class="bug">no caret here?!</span>
  this has caret
</div>

我的第1个设法主意是这是1个阅读器毛病,但是它在Chrome以及Firefox上是完整雷同的毛病!

拔出标记消逝的缘由是甚么?能否有处理方法?

推举谜底

没有晓得成绩切实其实切缘由,但是您不妨经由过程多种办法修复它。

我之前的说明():

这没有是毛病,叨教background color搁在<span>标志上(在
position:relative)在可实质div元素中,是以
Span位于可实质目次的顶部。

我依然以为这与z-index有闭,由于我们不妨在Chrome Focus边框顶部的白色配景下瞅到图象:

增除position:relative

增除<span>position:relative修复成绩:

数据-lang="js"数据-隐蔽="假"数据-掌握台="假"数据-巴贝我="假">

.no-bug {
  background-color: red;
}
<div contenteditable>
  This has caret
  <span class="no-bug">This has caret !</span>
  this has caret
</div>

z-index添减到<span>元素

添减背值z-index也能够处理此成绩:

数据-lang="js"数据-隐蔽="假"数据-掌握台="假"数据-巴贝我="假">

.no-bug {
  background-color: red;
  position: relative;
  z-index: ⑴0;
}
<div contenteditable>
  This has caret
  <span class="no-bug">This has caret !</span>
  this has caret
</div>

display: inline-block添减到<span>元素

添减display: inline-block(或者display: block)处理成绩:

数据-lang="js"数据-隐蔽="假"数据-掌握台="假"数据-巴贝我="假">

.no-bug {
  background-color: red;
  position: relative;
  display: inline-block;
}
<div contenteditable>
  This has caret
  <span class="no-bug">This has caret !</span>
  this has caret
</div>

其余客栈溢出相干成绩

    Edit cursor not displayed on Chrome in contenteditable

    contenteditable cursor doesn&#三九;t appear

佳了闭于为何拔出标记在可知足的With地位弗成睹:Relative?的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。