css - 从 css 写 html

标签 css escaping html

我很难通过 CSS 插入 html 标签并将其解释为 html。

我想写<noscript><h2>Please enable javascript!</h2></noscript>在所有页面的 h1 标题之后;所以我有

h1:after
{ 
content: "\003cnoscript\003e\003ch2\003ePlease enable javascript! \003c/h2\003e\003c/noscript\003e";
}

在我的 CSS 中。

虽然这成功写入了

<noscript><h2>Please enable javascript!</h2></noscript> 

它被视为字符串文字,并将其作为原始 h1 标题的一部分显示在页面上。

由于显而易见的原因,我不能为这个特定任务使用 javascript :P

最佳答案

来自 W3 :

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

<noscript> 中的内容在禁用 javascript 时显示。

关于css - 从 css 写 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13249919/

相关文章:

Javascript 在本地和服务器上的行为不同

javascript 将十六进制转义为字符串

javascript - 不需要在 javascript 中转义 innerHTML 字符?

javascript - jQuery SlideToggle 正在添加空白

html - HTML5 中有多少元素是脚本 API 的容器?

javascript - 我如何重新定位我以前的光滑箭头以使其可操作?

html - 如何让我的导航栏在滚动时保持在页面顶部?

html - 如何摆脱 IE 中文本区域的垂直滚动条?

java - 使用转义字符时出现问题 '{'

html - 为什么当宽度为 100% 时这个 div 会溢出?