How does the text-replace property work in css?

I took the exam. There I had a question:

Consider the following code:

body{text-replace: "a" "b" "b" "c"} 

What will the next line output if the replacement text style is implemented?

andy lives at the cafe


  • ndy lives behind cbfe
  • cndy lives cehind ccfe
  • andy lives at the cafe
  • andy lives cehind bafe

I could not find a link to the text-replace property in css.

+7
css
source share
1 answer

Wow! You stumbled upon a property that was the last in the 2007 GCPM specification and removed in the 2010 version. And in the online test! Either the test you are taking has been outdated for several years, or the one who installed it just pulled out of the random old versions of the W3C specifications and considered them all as relevant (since users, as you know, are here in Stack Overflow).

Because of how esoteric this is, I'm going to just answer the question. Of course, this answer is provided for educational purposes only. There is no text-replace property in any current CSS specification, and there has been almost a decade (neither in css-content nor css-gcpm ). Do not put it in your CSS and expect it to work. It will not be. If you need to replace text in an HTML document, use JavaScript.


Answer # 2: "cndy lives cehind ccfe"

The exact CSS example appears in the specification linked above, and the example is described as follows (emphasis mine):

The two rules below give the same result. In the first rule, all characters 'are converted to' b. Subsequently, all characters "b" are converted to "c.. In the second rule, all characters" a "and" b "are converted directly to" c.

 body { text-replace: "a" "b" "b" "c" } body { text-replace: "a" "c" "b" "c" } 

So, the processing order:

  • andy lives at the cafe
  • b ndy lives behind c b fe
  • c ndy lives c ehind c c fe
+19
source share

All Articles