我是靠谱客的博主 甜美紫菜,这篇文章主要介绍一招教你使用css3制作按钮添加动态效果(代码分享),现在分享给大家,希望可以做个参考。

css如何实现button按钮效果?

HTML结构:

首先定义一个body,使用button按钮,添加文字value设置为“开始游戏”以方便设置class转为id选择器。

复制代码
1
2
3
<body> <input id="search" name="cx" type="button" value="开始游戏" class="btn search"> </body>
登录后复制

效果代码

微信截图_20210906162714.png

效果出来了,能看到按钮效果了,但是没有给它添加动态装饰,通过使用css给它添加动态效果,一起看看怎么做。

css编辑代码:

1、在style之间,对search进行样式初始化,添加设置高度和宽度,然后使用设置背景background,设置no-repeat这个属性背景图将不会被重复。

复制代码
1
2
3
4
5
.search { width: 185px; height: 70px; background: url(images/btn_08.jpg) no-repeat center; }
登录后复制

代码效果

微信截图_20210906163541.png

2、接着,给css3按钮添加圆角效果设置属性每个border的四个值,最后设置居中对齐使用float: left

复制代码
1
2
3
4
5
border-radius: 8px; -webkit-border-radius: 8px; -o-border-radius: 8px; -moz-border-radius: 8px; float: left;
登录后复制

代码效果

QQ截图20210906164717.jpg

四点边圆角效果出来了

3、再给search进行样式添加字体大小、文本对齐方式、字体的粗细,设置border元素所有边框的样式、颜色、形状。

复制代码
1
2
3
4
5
6
7
8
font-size: 30px; text-align: center; font-weight: bold; border: none; color: #fff; cursor: pointer; line-height: 70px; font-family: 微软雅黑;
登录后复制

4、在style之间,对btn进行样式初始化,添加设置高度和宽度,然后使用设置背景background

复制代码
1
2
3
4
5
6
7
.btn { width: 383px; height: 70px;line-height: 0; border: 2px solid #a2f3ff; background: #f3682d; }
登录后复制

代码效果

微信截图_20210906165710.png

5、再给btn进行样式添加字体大小、文本对齐方式、字体的粗细,设置border元素所有边框的样式、颜色、形状。

复制代码
1
2
3
4
5
6
7
8
9
border-radius: 37px; -webkit-border-radius: 37px; -o-border-radius: 37px; -moz-border-radius: 37px; text-shadow: 3px 2px #d4481b; -webkit-text-shadow: 3px 2px #d4481b; -o-text-shadow: 3px 2px #d4481b; -moz-text-shadow: 3px 2px #d4481b; font-family: 微软雅黑;
登录后复制

代码效果

QQ截图20210906170209.jpg

6、将动画与search绑定

复制代码
1
2
#search{ animation: breathe 1.1s infinite;
登录后复制

7、使用@keyframes规则,创建动画。

复制代码
1
2
3
4
5
@keyframes breathe{ 0%{ transform: scale(.99); } 50%{ transform: scale(1.03); } 100%{ transform: scale(.99); } }
登录后复制

代码效果

GIF.gif

ok,编辑代码完成。

完整代码

复制代码
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>button按钮</title> <style type="text/css"> .search { width: 185px; height: 70px; background: url(images/btn_08.jpg) no-repeat center; border-radius: 8px; -webkit-border-radius: 8px; -o-border-radius: 8px; -moz-border-radius: 8px; float: left; font-size: 30px; text-align: center; font-weight: bold; border: none; color: #fff; cursor: pointer; line-height: 70px; font-family: 微软雅黑; } .btn { width: 383px; height: 70px;line-height: 0; border: 2px solid #a2f3ff; background: #f3682d; margin: 22px 0 0 17px; border-radius: 37px; -webkit-border-radius: 37px; -o-border-radius: 37px; -moz-border-radius: 37px; text-shadow: 3px 2px #d4481b; -webkit-text-shadow: 3px 2px #d4481b; -o-text-shadow: 3px 2px #d4481b; -moz-text-shadow: 3px 2px #d4481b; font-family: 微软雅黑; } #search{ animation: breathe 1.1s infinite; } @keyframes breathe{ 0%{ transform: scale(.99); } 50%{ transform: scale(1.03); } 100%{ transform: scale(.99); } } </style> </head> <body> <input id="search" name="cx" type="button" value="开始游戏" class="btn search"> </body> </html>
登录后复制

推荐学习:CSS3视频教程

以上就是一招教你使用css3制作按钮添加动态效果(代码分享)的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是甜美紫菜最近收集整理的关于一招教你使用css3制作按钮添加动态效果(代码分享)的全部内容,更多相关一招教你使用css3制作按钮添加动态效果(代码分享)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部