css3动画按钮_使用CSS3创建奇妙的动画按钮
css3动画按钮
How to Create a Pure CSS3 animated buttons Today I want to share some experience with creating interactive animated elements (buttons) with CSS3. In our example I going to use hover and active states of our buttons. Please pay attention that our demo will work in browsers that support used CSS3 properties.
如何创建纯CSS3动画按钮今天,我想分享一些使用CSS3创建交互式动画元素(按钮)的经验。 在我们的示例中,我将使用按钮的悬停和活动状态。 请注意,我们的演示将在支持二手CSS3属性的浏览器中运行。
现场演示
[sociallocker]
[社交储物柜]
下载结果
[/sociallocker]
[/ sociallocker]
Ok, download the example files and lets start coding !
好的,下载示例文件并开始编码!
步骤1. HTML (Step 1. HTML)
Here are full html code of our result. Pay attention to classes of buttons. In our experiment I used 2 different types of buttons. Each type have own behavior. Each button consist of few inner SPAN elements.
这是我们结果的完整html代码。 注意按钮的类别。 在我们的实验中,我使用了2种不同类型的按钮。 每种类型都有自己的行为。 每个按钮都包含几个内部SPAN元素。
index.html (index.html)
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8" />
<title>Pure CSS3 animated buttons | Script Tutorials</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/buttons.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container" id="container">
<div class="buttons">
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #1</span>
<span class="icon2"></span>
</a>
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #2</span>
<span class="icon2"></span>
</a>
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #3</span>
<span class="icon2"></span>
</a>
<div style="clear:both"></div>
<a href="#" class="but2">
<span class="title">Join us</span>
<span class="extra"><span>For a free</span></span>
<span class="icon"></span>
</a>
<a href="#" class="but2">
<span class="title">Try to search</span>
<span class="extra"><input type="text" /></span>
<span class="icon"></span>
</a>
<a href="#" class="but2">
<span class="title">Subscribe</span>
<span class="extra"><input type="text" /></span>
<span class="icon"></span>
</a>
</div>
</div>
<footer>
<h2>Pure CSS3 animated buttons</h2>
<a href="https://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a>
</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8" />
<title>Pure CSS3 animated buttons | Script Tutorials</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/buttons.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container" id="container">
<div class="buttons">
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #1</span>
<span class="icon2"></span>
</a>
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #2</span>
<span class="icon2"></span>
</a>
<a href="#" class="but1">
<span class="icon"></span>
<span class="title">Button #3</span>
<span class="icon2"></span>
</a>
<div style="clear:both"></div>
<a href="#" class="but2">
<span class="title">Join us</span>
<span class="extra"><span>For a free</span></span>
<span class="icon"></span>
</a>
<a href="#" class="but2">
<span class="title">Try to search</span>
<span class="extra"><input type="text" /></span>
<span class="icon"></span>
</a>
<a href="#" class="but2">
<span class="title">Subscribe</span>
<span class="extra"><input type="text" /></span>
<span class="icon"></span>
</a>
</div>
</div>
<footer>
<h2>Pure CSS3 animated buttons</h2>
<a href="https://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a>
</footer>
</body>
</html>
步骤2. CSS (Step 2. CSS)
Now – our CSS styles. First file is page layout
现在-我们CSS样式。 第一个文件是页面布局
css / main.css (css/main.css)
/* page layout */
*{
margin:0;
padding:0;
}
body {
color:#fff;
font:14px/1.3 Arial,sans-serif;
background:transparent url(../images/bg.gif) repeat top left;
}
footer {
background-color:#212121;
bottom:0;
box-shadow: 0 -1px 2px #111111;
-moz-box-shadow: 0 -1px 2px #111111;
-webkit-box-shadow: 0 -1px 2px #111111;
display:block;
height:70px;
left:0;
position:fixed;
width:100%;
z-index:100;
}
footer h2{
font-size:22px;
font-weight:normal;
left:50%;
margin-left:-400px;
padding:22px 0;
position:absolute;
width:540px;
}
footer a.stuts,a.stuts:visited{
border:none;
text-decoration:none;
color:#fcfcfc;
font-size:14px;
left:50%;
line-height:31px;
margin:23px 0 0 110px;
position:absolute;
top:0;
}
footer .stuts span {
font-size:22px;
font-weight:bold;
margin-left:5px;
}
.container {
margin:20px auto;
padding:20px;
position:relative;
width:800px;
}
/* page layout */
*{
margin:0;
padding:0;
}
body {
color:#fff;
font:14px/1.3 Arial,sans-serif;
background:transparent url(../images/bg.gif) repeat top left;
}
footer {
background-color:#212121;
bottom:0;
box-shadow: 0 -1px 2px #111111;
-moz-box-shadow: 0 -1px 2px #111111;
-webkit-box-shadow: 0 -1px 2px #111111;
display:block;
height:70px;
left:0;
position:fixed;
width:100%;
z-index:100;
}
footer h2{
font-size:22px;
font-weight:normal;
left:50%;
margin-left:-400px;
padding:22px 0;
position:absolute;
width:540px;
}
footer a.stuts,a.stuts:visited{
border:none;
text-decoration:none;
color:#fcfcfc;
font-size:14px;
left:50%;
line-height:31px;
margin:23px 0 0 110px;
position:absolute;
top:0;
}
footer .stuts span {
font-size:22px;
font-weight:bold;
margin-left:5px;
}
.container {
margin:20px auto;
padding:20px;
position:relative;
width:800px;
}
And now – styles of our buttons
现在-我们按钮的样式
css / buttons.css (css/buttons.css)
/*buttons #1*/
.buttons {
overflow:hidden;
}
.but1{
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
-moz-box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
-webkit-box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
background-color:#f4f5fe;
display:block;
float:left;
margin:10px;
overflow:hidden;
padding:10px 15px;
position:relative;
text-decoration:none;
transition:all 0.5s ease-in-out;
-moz-transition:all 0.5s ease-in-out;
-o-transition:all 0.5s ease-in-out;
-webkit-transition:all 0.5s ease-in-out;
}
.but1 .icon{
background:transparent url(../images/download.png) no-repeat top left;
float:left;
height:32px;
width:45px;
transition:all 0.5s ease-in-out;
-moz-transition:all 0.5s ease-in-out;
-o-transition:all 0.5s ease-in-out;
-webkit-transition:all 0.5s ease-in-out;
}
.but1 .title{
font-size:18px;
color:#000;
display:block;
float:left;
font-weight:bold;
line-height:32px;
}
.but1 .icon2{
background:transparent url(../images/download2.png) no-repeat top left;
height:32px;
left:20px;
opacity:0;
position:absolute;
top:-15px;
width:32px;
}
.but1:hover{
background-color:#e3e3ff;
box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-moz-box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-webkit-box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-webkit-transition-delay: 0.5s;
-moz-transition-delay: 0.5s;
-o-transition-delay: 0.5s;
-ms-transition-delay: 0.5s;
transition-delay: 0.5s;
}
.but1:hover .icon{
transform:rotate(-90deg) scale(0.8);
-ms-transform:rotate(-90deg) scale(0.8);
-moz-transform:rotate(-90deg) scale(0.8);
-o-transform:rotate(-90deg) scale(0.8);
-webkit-transform:rotate(-90deg) scale(0.8);
}
.but1:active .icon{
opacity:0;
}
.but1:active .icon2{
opacity:1;
-webkit-animation:slideDown1 1.0s linear infinite;
-moz-animation:slideDown1 1.0s linear infinite;
animation:slideDown1 1.0s linear infinite;
}
.but1:active{
background-color:#c1c1ff;
box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
-moz-box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
-webkit-box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
}
@keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
@-webkit-keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
@-moz-keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
/*buttons #2*/
.but2{
border-radius:15px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
background-color:#99cc99;
float:left;
height:40px;
margin:10px;
overflow:hidden;
padding-left:20px;
position:relative;
text-decoration:none;
transition:all 0.5s linear;
-moz-transition:all 0.5s linear;
-o-transition:all 0.5s linear;
-webkit-transition:all 0.5s linear;
}
.but2 .title{
color:#000000;
display:block;
float:left;
font-size:18px;
font-weight:bold;
line-height:40px;
transition:all 0.2s linear;
-moz-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
-webkit-transition:all 0.2s linear;
}
.but2 .extra{
background-color:#63707e;
color:#fff;
float:left;
font-size:18px;
line-height:40px;
opacity:0;
position:relative;
text-transform:uppercase;
width:0px;
transition:all 0.3s linear;
-moz-transition:all 0.3s linear;
-o-transition:all 0.3s linear;
-webkit-transition:all 0.3s linear;
}
.but2 .extra span, .but2 .extra input {
display:none;
}
.but2 .icon{
background:transparent url(../images/right.png) no-repeat center center;
float:left;
height:40px;
width:40px;
transition:all 0.3s linear;
-moz-transition:all 0.3s linear;
-o-transition:all 0.3s linear;
-webkit-transition:all 0.3s linear;
}
.but2:hover .extra span, .but2:hover .extra input{
display:inline-block;
}
.but2:hover .extra{
margin-left:10px;
opacity: 1;
padding-left:10px;
padding-right:10px;
text-align:center;
width:150px;
}
.but2:hover .icon{
transform:rotate(180deg);
-ms-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
-webkit-transform:rotate(180deg);
}
/*buttons #1*/
.buttons {
overflow:hidden;
}
.but1{
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
-moz-box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
-webkit-box-shadow:0px 0px 7px rgba(0,0,0,0.4) inset, 0px 0px 0px 4px rgba(255,255,255,0.1);
background-color:#f4f5fe;
display:block;
float:left;
margin:10px;
overflow:hidden;
padding:10px 15px;
position:relative;
text-decoration:none;
transition:all 0.5s ease-in-out;
-moz-transition:all 0.5s ease-in-out;
-o-transition:all 0.5s ease-in-out;
-webkit-transition:all 0.5s ease-in-out;
}
.but1 .icon{
background:transparent url(../images/download.png) no-repeat top left;
float:left;
height:32px;
width:45px;
transition:all 0.5s ease-in-out;
-moz-transition:all 0.5s ease-in-out;
-o-transition:all 0.5s ease-in-out;
-webkit-transition:all 0.5s ease-in-out;
}
.but1 .title{
font-size:18px;
color:#000;
display:block;
float:left;
font-weight:bold;
line-height:32px;
}
.but1 .icon2{
background:transparent url(../images/download2.png) no-repeat top left;
height:32px;
left:20px;
opacity:0;
position:absolute;
top:-15px;
width:32px;
}
.but1:hover{
background-color:#e3e3ff;
box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-moz-box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-webkit-box-shadow:0px 0px 4px rgba(0,0,0,0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.5);
-webkit-transition-delay: 0.5s;
-moz-transition-delay: 0.5s;
-o-transition-delay: 0.5s;
-ms-transition-delay: 0.5s;
transition-delay: 0.5s;
}
.but1:hover .icon{
transform:rotate(-90deg) scale(0.8);
-ms-transform:rotate(-90deg) scale(0.8);
-moz-transform:rotate(-90deg) scale(0.8);
-o-transform:rotate(-90deg) scale(0.8);
-webkit-transform:rotate(-90deg) scale(0.8);
}
.but1:active .icon{
opacity:0;
}
.but1:active .icon2{
opacity:1;
-webkit-animation:slideDown1 1.0s linear infinite;
-moz-animation:slideDown1 1.0s linear infinite;
animation:slideDown1 1.0s linear infinite;
}
.but1:active{
background-color:#c1c1ff;
box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
-moz-box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
-webkit-box-shadow:0 2px 4px rgba(0, 0, 0, 0.5) inset, 0px 0px 0px 4px rgba(51,51,204,0.8);
}
@keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
@-webkit-keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
@-moz-keyframes slideDown1{
0% {
top: -30px;
}
100% {
top: 55px;
}
}
/*buttons #2*/
.but2{
border-radius:15px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
background-color:#99cc99;
float:left;
height:40px;
margin:10px;
overflow:hidden;
padding-left:20px;
position:relative;
text-decoration:none;
transition:all 0.5s linear;
-moz-transition:all 0.5s linear;
-o-transition:all 0.5s linear;
-webkit-transition:all 0.5s linear;
}
.but2 .title{
color:#000000;
display:block;
float:left;
font-size:18px;
font-weight:bold;
line-height:40px;
transition:all 0.2s linear;
-moz-transition:all 0.2s linear;
-o-transition:all 0.2s linear;
-webkit-transition:all 0.2s linear;
}
.but2 .extra{
background-color:#63707e;
color:#fff;
float:left;
font-size:18px;
line-height:40px;
opacity:0;
position:relative;
text-transform:uppercase;
width:0px;
transition:all 0.3s linear;
-moz-transition:all 0.3s linear;
-o-transition:all 0.3s linear;
-webkit-transition:all 0.3s linear;
}
.but2 .extra span, .but2 .extra input {
display:none;
}
.but2 .icon{
background:transparent url(../images/right.png) no-repeat center center;
float:left;
height:40px;
width:40px;
transition:all 0.3s linear;
-moz-transition:all 0.3s linear;
-o-transition:all 0.3s linear;
-webkit-transition:all 0.3s linear;
}
.but2:hover .extra span, .but2:hover .extra input{
display:inline-block;
}
.but2:hover .extra{
margin-left:10px;
opacity: 1;
padding-left:10px;
padding-right:10px;
text-align:center;
width:150px;
}
.but2:hover .icon{
transform:rotate(180deg);
-ms-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
-webkit-transform:rotate(180deg);
}
现场演示
结论 (Conclusion)
Thats all, all was really easy, isn’t it? The result was great. I hope that our nice tips help you. Good luck!
就这样,一切真的很简单,不是吗? 结果很棒。 希望我们的好提示对您有所帮助。 祝好运!
翻译自: https://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/
css3动画按钮
上一篇: iOS 滑动返回手势
推荐阅读
-
css3动画按钮_使用CSS3创建奇妙的动画按钮
-
iOS使用核心动画和粒子发射器实现点赞按钮的方法
-
5种漂亮的纯CSS3动画按钮特效_html/css_WEB-ITnose
-
一款纯css3实现的动画按钮_html/css_WEB-ITnose
-
一款纯css3实现的动画按钮_html/css_WEB-ITnose
-
css3动画简介以及动画库animate.css的使用_html/css_WEB-ITnose
-
使用CSS3的animation steps属性实现跳帧动画
-
如何使用css3实现一个类在线直播的队列动画的示例代码
-
css3动画简介以及动画库animate.css的使用_html/css_WEB-ITnose
-
CSS3 按钮边框动画的实现