如何在“之前”应用伪元素。在多行程中

发布于 2025-01-29 11:55:41 字数 1428 浏览 3 评论 0原文

在下面的图像上,我有两个跨度:一个带有红色边框的跨度(在第一行的一部分附近),另一个带有绿色边界(第二行和第三行的一部分)。如您所见,第二个跨度正确地包裹了两行。

然后,我将这两个跨度(当然是“显示:相对”跨度)与“伪元素”之前的红色和绿色alpha背景(出于与重叠注释规格链接的特定原因(出于特定原因) ,与此主题无关​​,是这样构建的伪元素:

    @mixin annotColors($color, $alpha) {
        border-color: $color!important;
        &:before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: rgba($color, $alpha);
            pointer-events: none;
        }
    }

    $annot-base-alpha: .25;
    &[data-annottype="dft"] { @include annotColors($color-annot-default, $annot-base-alpha); }
    &[data-annottype="sugg"] { @include annotColors($color-annot-suggestion, $annot-base-alpha); }
    &[data-annottype="good"] { @include annotColors($color-annot-good, $annot-base-alpha); }
    &[data-annottype="err"] { @include annotColors($color-annot-error, $annot-base-alpha); }
    &[data-annottype="hvy"] { @include annotColors($color-annot-heavy, $annot-base-alpha); }
    &[data-annottype="xhw"] { @include annotColors($color-annot-comprehension, $annot-base-alpha); 

正如您所看到的,第二个(绿色)背景不符合其多层次的跨度,而是[左至左下行,右半线]区域。您是否知道我该如何强制:在“同伴”的“多利父母”之前?

On the following image, I have two spans: one with red border (around a part of the first line) and one with green borders (around a part of second and third line). The second span, as you see, correctly wrap in two line.

enter image description here

Then, I link those two spans ("display: relative" spans, of course) with corresponding red and green alpha backgrounds in ":before" pseudo-elements (for specific reasons linked to overlapping annotations specifications, not related to this topic), pseudo-elements constructed like this:

    @mixin annotColors($color, $alpha) {
        border-color: $color!important;
        &:before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: rgba($color, $alpha);
            pointer-events: none;
        }
    }

    $annot-base-alpha: .25;
    &[data-annottype="dft"] { @include annotColors($color-annot-default, $annot-base-alpha); }
    &[data-annottype="sugg"] { @include annotColors($color-annot-suggestion, $annot-base-alpha); }
    &[data-annottype="good"] { @include annotColors($color-annot-good, $annot-base-alpha); }
    &[data-annottype="err"] { @include annotColors($color-annot-error, $annot-base-alpha); }
    &[data-annottype="hvy"] { @include annotColors($color-annot-heavy, $annot-base-alpha); }
    &[data-annottype="xhw"] { @include annotColors($color-annot-comprehension, $annot-base-alpha); 

And as you can see, the second (green) background does not fit its multilined span, but rather it's [left-first line, right-last line] zone. Would you have any idea how I could force that :before to "fellow" it multilined parents?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兰花执着 2025-02-05 11:55:41

好的,我找到了一个非常可怕的解决方案,但至少它有效。代替:

<span class="annotation">some text</span>

用:

.annotation {
  position: relative;
  background-color: white;
  &:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba($green, .5);
  }
}

的每个字母包裹在xml标签中(selection = selection.replaceall(/

<span class="annotation"><x>s</x><x>o</x><x>m</x><x>e</x><x> </x><x>t</x><x>e</x><x>x</x><x>t</x></span>

.annotation {
  background-color: white;
  &>x {
    position: relative;
    &:before {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: rgba($green, .5);
    }
  }
}

我将文本 (尤其是对于大型选择),但就我而言,它没有导致任何渲染问题。

OK, I found a quite horrible solution, but at least it works. In place of having:

<span class="annotation">some text</span>

with:

.annotation {
  position: relative;
  background-color: white;
  &:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba($green, .5);
  }
}

I wrap each letters of the text in an xml tag (selection = selection.replaceAll(/(.)/g, '$1')):

<span class="annotation"><x>s</x><x>o</x><x>m</x><x>e</x><x> </x><x>t</x><x>e</x><x>x</x><x>t</x></span>

which hold the :before translucid color:

.annotation {
  background-color: white;
  &>x {
    position: relative;
    &:before {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: rgba($green, .5);
    }
  }
}

That overloads the innerHTML (especially for big selections), but as far as I tried it results in no rendering problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文