4

I want to transform all text within curly brackets into a link using CSS selectors. I could write it in JavaScript, but I'm wondering whether it can be added in CSS like this:

p:before {
    content: "<a href'http://example.com/t2'>";
}

p:after {
    content: "</a>";
}

The t2 in the href would be a copy of the text inside the curly brackets.

In the example above all of the text inside the p is transformed into a link, but is there a way to select only stuff inside curly braces?

Ben
  • 51,770
  • 36
  • 127
  • 149
Matt Parkins
  • 24,208
  • 8
  • 50
  • 59

3 Answers3

5

Simple answer: You can't, because this is not what Cascading Style Sheets are made for. Use JavaScript

Michel Feldheim
  • 17,625
  • 5
  • 60
  • 77
2

It's generally a good idea to use Javascript for this kind of thing.

CSS is best suited for manipulating presentational aspects of your page.

What you're trying to do here is to manipulate the page content, for which Javascript is just the thing.

Chamila Chulatunga
  • 4,856
  • 15
  • 17
0

CSS cannot be used to create links. Such things are best handled when generating the page, e.g. in server-side scripting. If you do it in client-side JavaScript, search engines will not see the links.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390