分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

CSS画图

发布时间:2023-09-06 02:29责任编辑:郭大石关键词:CSS

原理是利用边框实现,好处是不用加载图片,节省流量;坏处就是会有很长一段css样式

基本:1.设置width,height为0 ,然后设置一个border-width

利用border可以画很多有趣的图

1.正方形

?
1
2
3
4
5
6
7
#square{
width:0px;
height:0px;
border-width: 100px;
border-style: solid;
border-color: blue red green yellow;
}

2.三角形:设置其他边颜色为透明值transparent

?
1
2
3
4
5
6
7
#triangle{
width: 0px;
height: 0px;
border-width: 100px;
border-style: solid;
border-color: blue transparent transparent transparent;
}

3.圆形:设置圆角属性border-radius

?
1
2
3
4
5
6
7
8
#circle{
width:0px;
height:0px;
border-width: 100px;
border-style: solid;
border-color: blue red green yellow;
border-radius: 100px;
}

4.扇形:同理设置透明色

?
1
2
3
4
5
6
7
8
#fan{
width: 0px;
height: 0px;
border-width: 100px;
border-style: solid;
border-color: transparent transparent transparent yellow;
border-radius: 100px;
}

5.同心圆:在圆的基础上添加width/height值

?
1
2
3
4
5
6
#circle-circle{
width: 200px;
height: 200px;
border: 50px solid red;
border-radius: 200px;
}

5.半圆:利用border-radius分别设置左上角,右上角,右下角,左下角的值

?
1
2
3
4
5
6
7
8
#circle-half{
width: 200px;
height: 100px;
background-color: red;
/*border-color: red;*/
/*border-style: solid;*/
border-radius: 100px 100px 0 0;
}

6.四分之一圆:同半圆原理

?
1
2
3
4
5
6
#circle-double-half{
width: 200px;
height: 200px;
background-color: red;
border-radius: 200px 0 0 0;
}

7.小尾巴 :主要是在半圆的基础上添加某一侧的Border,border-top,border-right,border-left,border-bottom,大家阔以动手试一试

?
1
2
3
4
5
6
7
8
#tail{
width: 100px;
height: 100px;
border-radius: 100px 0 0 0;
border-top:30px solid red;
/*border-radius: 0 100px 0 0;
border-top: 30px solid red;*/
}

8.提示框:用到了:after伪类去实现小尾巴的功能

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pop{
margin-top: 20px;
width: 400px;
height: 200px;
border-radius: 20px;
background-color: red;
position: relative;
}
#pop:after{
content: "";
height: 100px;
width:100px;
border-radius: 0 0 200px 0;
border-right: 50px solid red;
position: absolute;
top:180px;
}

9.椭圆:这里用到border-radius:100px / 50px,其中"/"前面的表示水平半径(其值为width/2),后面的表示垂直半径(其值为height/2).

?
1
2
3
4
5
6
7
#ellipse{
margin-top: 20px;
width: 200px;
height: 100px;
border-radius: 100px/50px;
background-color: red;
}

10.梯形:主要是理解Border属性,也就是第一幅图,梯形就比较容易画了

?
1
2
3
4
5
6
7
8
#trapezium {
height: 0;
width: 200px;
border-bottom: 100px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
}

11.菱形:主要是用到旋转transform,不过要考虑到浏览器内核不同,要实现兼容,我这里就省略了

?
1
2
3
4
5
6
#diamond {
width: 100px;
height: 100px;
background-color: red;
transform:rotate(-45deg);
}

12.平行四边形:也是主要用到transform,但菱形用的是skew,倾斜

?
1
2
3
4
5
6
#parallelogram {
width:160px;
height: 100px;
background-color: red;
transform:skew(30deg);
}

13.五角星:主要是画三个三角形,通过旋转,然后拼接成一个五角星,各种画法自己去体会.....(可以通过不同的三角形去拼接,但原理是一样的)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#star{
width: 0;
height: 0;
color: red;
position: relative;
border-left: 100px solid transpar
我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved