图形包括基本的矩形、圆形、椭圆、三角形、多边形,也包括稍微复杂一点的爱心、钻石、阴阳八卦。其中绝大部分涉及到CSS3中的border-radius,text-shadow,transform
等一些比较复杂的属性,所以需要有一点CSS3基础的最好。特别注意的是此效果不兼容IE<9的浏览器,最好用firefox,chrome等浏览器。以下案例都由本人亲自测试,希望好学您也可以一一测试一下。
1.正方形
正方形
1 #square {
2 width: 100px;
3 height: 100px;
4 background: red;
5 }
2.长方形
长方形
1 #rectangle {
2 width: 200px;
3 height: 100px;
4 background: red;
5 }
3.圆形
圆形
1 #circle {
2 width: 100px;
3 height: 100px;
4 background: red;
5 -moz-border-radius: 50px;
6 -webkit-border-radius: 50px;
7 border-radius: 50px;
8 }
4.椭圆
椭圆
1 #oval {
2 width: 200px;
3 height: 100px;
4 background: red;
5 -moz-border-radius: 100px / 50px;
6 -webkit-border-radius: 100px / 50px;
7 border-radius: 100px / 50px;
8 }
5.上三角
上三角
1 #triangle-up {
2 width: 0;
3 height: 0;
4 border-left: 50px solid transparent;
5 border-right: 50px solid transparent;
6 border-bottom: 100px solid red;
7 }
6.下三角
下三角
1 #triangle-down {
2 width: 0;
3 height: 0;
4 border-left: 50px solid transparent;
5 border-right: 50px solid transparent;
6 border-top: 100px solid red;
7 }
7.左三角
左三角