仅使用 CSS 将锚标记替换为不同的文本

ded*_*man 4 html css google-chrome-extension

我想仅使用 CSS 将锚标记替换为一些不同的文本。我尝试过使用 CSS 伪元素,但使用它会将新文本放入锚标记内,这不是预期的。我想替换整个锚标记,以便新文本不会有任何链接。

原始代码:

<a href="www.google.com" class="link-class">The google link</a>
<a href="www.yahoo.com" class="link-class">The yahoo link</a>
<a href="www.so.com">Don't replace this</a>
<a href="www.ddgo.com" class="link-class">The ddgo link</a>
Run Code Online (Sandbox Code Playgroud)

更换后:

Replacement text
Replacement text
<a href="www.so.com">Don't replace this</a>
Replacement text
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个:

<a href="www.google.com" class="link-class">The google link</a>
<a href="www.yahoo.com" class="link-class">The yahoo link</a>
<a href="www.so.com">Don't replace this</a>
<a href="www.ddgo.com" class="link-class">The ddgo link</a>
Run Code Online (Sandbox Code Playgroud)
Replacement text
Replacement text
<a href="www.so.com">Don't replace this</a>
Replacement text
Run Code Online (Sandbox Code Playgroud)

简而言之,我不想在替换的文本上使用超链接,如何仅使用 CSS 来做到这一点?


我通过 my 为特定页面执行此操作extension,并且页面通过 ajax 请求加载其 DOM 内容,因此在这种情况下使用 JS 来完成这个小任务变得非常麻烦。

Bha*_*ama 5

尝试用这个.link-class:after

  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: black;
Run Code Online (Sandbox Code Playgroud)

  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: black;
Run Code Online (Sandbox Code Playgroud)
.link-class {
  visibility: hidden;
  position: relative;
}

.link-class:after {
  visibility: visible;
  content: 'Replacement text';
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: black;
}
Run Code Online (Sandbox Code Playgroud)