css :before 和 :after

:before p:before 在每个 <p> 元素的内容之前插入内容。 2
:after p:after 在每个 <p> 元素的内容之后插入内容。 2

<!DOCTYPE html>
<html>
<head>
<style>
p:before
{
content:"台词:";
}
</style>
</head>

<body>

<p>我是唐老鸭。</p>
<p>我住在 Duckburg。</p>

<p><b>注释:</b>对于在 IE8 中工作的 :before,必须声明 DOCTYPE。</p>

</body>
</html>

效果:

台词:我是唐老鸭。

台词:我住在 Duckburg。

台词:注释:对于在 IE8 中工作的 :before,必须声明 DOCTYPE。

<!DOCTYPE html>
<html>
<head>
<style>
p:after
{
content:"- 台词";
}
</style>
</head>

<body>

<p>我是唐老鸭。</p>
<p>我住在 Duckburg。</p>

<p><b>注释:</b>对于在 IE8 中工作的 :after,必须声明 DOCTYPE。</p>

</body>
</html>

效果:

我是唐老鸭。- 台词

我住在 Duckburg。- 台词

注释:对于在 IE8 中工作的 :after,必须声明 DOCTYPE。- 台词

原文地址:https://www.cnblogs.com/h2zZhou/p/8043712.html