使用 :before 和 :after CSS 选择器插入 Html

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5865937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:23:42  来源:igfitidea点击:

Using :before and :after CSS selector to insert Html

htmlcsscss-selectors

提问by Vik

I'm wondering if the following is possible. I know it doesnt work, but maybe I'm not writing it in the correct syntax.

我想知道以下是否可能。我知道它不起作用,但也许我没有用正确的语法编写它。

li.first div.se_bizImg:before{
    content: "<h1>6 Businesses Found <span class="headingDetail">(view all)</span></h1>";
}

Anyway of doing this?

无论如何要这样做?

回答by Erik Martino

contentdoesn't support HTML, only text. You should probably use javascript, jQuery or something like that.

content不支持 HTML,只支持文本。您可能应该使用 javascript、jQuery 或类似的东西。

Another problem with your code is "inside a "block. You should mix 'and "(class='headingDetail').

您的代码的另一个问题是""块内。你应该混合'"( class='headingDetail')。

If contentdid support HTML you could end up in an infinite loop where contentis added inside content.

如果content确实支持 HTML,您可能会陷入无限循环,其中content添加了content.