返回到:CSS 伪元素 | CSS教程
定义和说明
:after 选择器向选定元素的最后子元素后面插入内容。
使用content 属性来指定要插入的内容。
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | 谷歌 | IE | 火狐 | 苹果 | opera |
---|---|---|---|---|---|
::after | 4.0 | 9.0 部分从 8.0 | 3.5 | 3.1 | 7.0 部分从4.0 |
注意: after在IE8中运行,必须声明<!DOCTYPE> 。
实例
每个<p>元素之后插入内容:
HTML
xxxxxxxxxx
21
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Web176教程网(web176.com)</title>
6
<style>
7
p:after
8
{
9
content:"- 注意我";
10
}
11
</style>
12
</head>
13
14
<body>
15
<p>我的名字是 Donald</p>
16
<p>我住在 Ducksburg</p>
17
18
<p><b>注意:</b> :after在IE8中运行,必须声明 !DOCTYPE </p>
19
20
</body>
21
</html>
在每个 <p>之后插入的内容和样式:
HTML
xxxxxxxxxx
24
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Web176教程网(web176.com)</title>
6
<style>
7
p:after
8
{
9
content:"- Remember this";
10
background-color:yellow;
11
color:red;
12
font-weight:bold;
13
}
14
</style>
15
</head>
16
17
<body>
18
<p>My name is Donald</p>
19
<p>I live in Ducksburg</p>
20
21
<p><b>注意:</b>:after作用于IE8 以及更早版本的浏览器,DOCTYPE 必须已经声明.</p>
22
23
</body>
24
</html>
阅读剩余 62%
作者:terry,如若转载,请注明出处:https://www.web176.com/cssprop/5329.html