Change Link text with CSS

Viewed 21502

I want to change my link Text with CSS, but it doesn't work.

a.testclass {
  display: none;
}

a.testclass:after {
  content: 'new text';
}
<a class="testclass;" href="someurl.com"> CHANGE THIS HERE </a>

Display none works for me but not the new text.

4 Answers

You can hide the original text by using font-size:0; then adding the original font size back to your after:

a.testclass {
  font-size:0;
}

a.testclass:after {
  content: 'new text';
  font-size:16px;         /* original font size */
}
<a class="testclass" href="someurl.com"> CHANGE THIS HERE </a>

Use font-size: 0 to hide the original text. To restore the original size use font-size: initial. You won't need to care about the original value.

a.testclass {
  font-size: 0;
}

a.testclass:after {
  content: 'new text';
  font-size: initial;
}

Try This:

a.testclass:after{
content: 'new text';
}
<a class="testclass" href="someurl.com"> </a>

Try This one

a.testclass {
  visibility:hidden;
}
a.testclass:before {
  content: 'new text';
  visibility:visible;
}
<a class="testclass" href="example.com">Link</a>

Related