为什么不可能改变css中的内容? [英] Why is it impossible to change content in css?

查看:125
本文介绍了为什么不可能改变css中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS2.1伪选择器,例如 :: after :: before 允许添加文本内容这一页。例如:

CSS2.1 pseudo-selectors such as ::after and ::before allows to add text content to the page. For example :

CSS

 p:after { content:' Batman!' }

HTML

<p>Na Na Na Na Na Na</p>

在浏览器中输出

Na Na Na Na Na Na Batman!






我的问题,使用相同的HTML源代码为什么一块CSS

 p { content:'My hero is' }
 p:after { content:' Batman!' }

不输出此

My hero is Batman!

但是输出结果?

Na Na Na Na Na Na Batman!






content属性的w3c规格: http://www.w3.org/TR/CSS21/generate.html#propdef -content

回答 - 我正在查看CSS2.1规格。 CSS3规范表示即使没有也可能: :after :: before 伪选择器。

Answer - I was looking at the CSS2.1 spec. The CSS3 spec indicates it is possible even without ::after and ::before pseudo-selectors. But not every browser implements it.


  • Chrome 20.0.1132.57 :NO

  • Opera 12.00 r1467 :是

  • Safari 5.1.7(7534.57.2) $ b
  • IE 8.0.7601 :NO(尚未实现CSS2内容属性)

  • Chrome 20.0.1132.57 : NO
  • Opera 12.00 r1467 : YES
  • Safari 5.1.7 (7534.57.2) : NO
  • IE 8.0.7601 : NO (the CSS2 content property is not even implemented)

推荐答案

CSS 2.1规范引用说:适用于::before和:after伪元素。在 CSS3生成和替换内容模块的草稿中放宽了此限制,该模板是旧的(2003年)和过时但仍部分实施。对于普通元素,Opera似乎支持 content ,但使用的是URL值(用于插入图片),而Chrome和Safari只做 >用于URL值。所以你的代码实际上是在Safari上工作。

The CSS 2.1 spec cited says: "Applies to: :before and :after pseudo-elements". This restriction has been relaxed in the draft for CSS3 Generated and Replaced Content Module, which is old (2003) and outdated but still partly implemented. Opera seems to support content for normal elements, except for the use of URL values (used to insert images), whereas Chrome and Safari do the same only for URL values. So you code actually works on Safari.

更广泛的支持不太可能,除非模块的规范工作取得一些进展。在W3C CSS模块状态页上,该模块位于重写部分中,注释严重过时。

More widespread support is not very likely unless specification work on the module makes some progress. On the W3C CSS module status page, the module is in the "Rewriting" section, with the note "Severely outdated".

这篇关于为什么不可能改变css中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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