在CSS中文本替换属性如何工作? [英] How text-replace property work in css?

查看:173
本文介绍了在CSS中文本替换属性如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在参加测试。我有以下问题:


请考虑以下代码:

  body {text-replace:abbc} 


b $ b

如果实现了文本替换样式,则以下字符串的输出是什么?



andy住在咖啡馆后 / p>





  1. ndy住在cbfe后

  2. cndy lives cehind ccfe

  3. andy住在咖啡馆后

  4. andy lives cehind bafe




我找不到css中文本替换属性的任何引用。

解决方案

哇!您偶然发现了 2007 GCPM规范中的最后一个资源。并在2010年版本中删除。并在在线测试!要么你的测试是几年过时,或者谁设置它只是从随机的旧版本的W3C规范,并把它们所有相关的(因为用户已知在这里做Stack Overflow)。 p>

因为这是多么深奥,我要回答这个问题。不用说,这个答案只是教育目的。在任何当前的CSS规范中都没有 文本替换属性,并且没有存在几十年(在 css-content css-gcpm )。不要把它放在你的CSS,并期望它的工作。 不会。如果您需要在HTML文档中进行文本替换,请使用JavaScript。






答案是#2:cndy lives cehind ccfe



精确的CSS示例出现在规范中,链接上面,示例描述如下强调我的):


下面的两个规则产生相同的结果。 在第一个规则中,所有a个字符都将转换为b。 在第二个规则中,所有的'a'和'b'字符都直接转换为'c'。

  body {text-replace:abbc} 
body {text-replace:ac bc}


/ p>


  1. andy住在咖啡厅后

  2. b > b fe

  3. c ndy住在 c ehind c c fe


I was taking a test in upwork. There I got the following question:

Consider the following code:

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

What will be the output of the following string if the text replace style is implemented?

andy lives behind cafe


  1. ndy lives behind cbfe
  2. cndy lives cehind ccfe
  3. andy lives behind cafe
  4. andy lives cehind bafe

I couldn't find any reference for the text-replace property in css.

解决方案

Wow! You've stumbled upon a property that was last in the 2007 GCPM specification and removed in the 2010 revision. And in an online test at that! Either the test you're taking is several years out of date, or whoever set it was just pulling from random old revisions of W3C specifications and treating them all as relevant (as users have been known to do here on Stack Overflow).

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


The answer is #2: "cndy lives cehind ccfe"

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

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

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

So the processing order goes:

  1. andy lives behind cafe
  2. bndy lives behind cbfe
  3. cndy lives cehind ccfe

这篇关于在CSS中文本替换属性如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆