注意:css
应用举例:使用一个<div>标签生成一个加号(宽150px,高50px),如图:html
实现思路以下:spa
首先定义一个中心为页面中心的150*150的div标签,而后利用before与after伪元素向div标签中添加一个横向与一个纵向的红色矩形.net
实现代码以下:code
html:htm
<div class="jia"></div>
css:it
.jia{ position:absolute; width:150px; height:150px; top:50%; left:50%; margin-left:-75px; margin-top:-75px; } .jia::before,.jia::after{ position:absolute; background-color:red; content:"" } .jia::before{ width:150px; height:50px; top:50px; } .jia::after{ width:50px; height:150px; left:50px; }