Quantcast
Channel: webdesigncrowd.com » Web Development
Viewing all articles
Browse latest Browse all 31

CSS Animated Buttons With Icons

$
0
0

Introduction

CSS buttons have progressed so far with the help of CSS3. I saw some beautiful buttons from the website but those were all achieved by images. I wanted to recreate that style with CSS only. Using css border tricks to make the triangle arrows and box shadows to create the 3D effect, I created a simple CSS only button that looks just as good. Add transitions to add a little animation and you have a great looking animated button.

HTML Structure

The HTML is just a generic button with some embedded span classes to make the effects. There is a left and right class that determines where the icon is. The inner span classes also have these classes.

<a href="#" class="btn left">
  <span class="left icon icon-heart"><span class="arrow-left"></span></span>
  <span class="right title">Favorite This!</span>
</a>

CSS Styles

The CSS may be a little sloppy so feel free to optimize and customize the code. But basically there is a base button and inner span icon and span title. There are also arrows or slants that add a bit of flare to the button. These are also animated on hover. Again, this can be trimmed down to what you need. That’s all there is to these animated buttons.

/* Button styles */
.btn {
  box-sizing:border-box;
   -moz-box-sizing:border-box;
   -webkit-box-sizing:border-box;
  
  position: relative;
  display: inline-block;
  overflow: hidden;
  height: 53px;
  
  border-radius: 6px;
  -moz-border-radius: 6px;
  -webkit-border-radius: 6px;
    
  line-height: 30px;
  font-size: 16px;
  font-weight: bold;
  text-shadow: 0px 1px 1px #888;
}

  .btn span.icon, .btn span.title {
    display: block;
    position: relative;
    line-height: 50px;
    padding: 0 30px;  
    
    border-radius: 6px;
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;  
  }
    
    .btn span.left {
      float: left;
      
      border-radius: 6px 0 0 6px;
      -moz-border-radius: 6px 0 0 6px;
      -webkit-border-radius: 6px 0 0 6px;
    }
    .btn span.right {
      float: right;
      
      border-radius: 0 6px 6px 0;
      -moz-border-radius: 0 6px 6px 0;
      -webkit-border-radius: 0 6px 6px 0;
    }
    
  .btn span.icon {
    font-size: 23px;
    background-color: #00967f;    
    
    -webkit-box-shadow: 0 3px 0 0 #007261;
    box-shadow: 0 3px 0 0 #007261;
    text-shadow: 0px 1px 1px #888;
  }
  .btn span.title {        
    -webkit-box-shadow: 0 3px 0 0 #00ae94;
    box-shadow: 0 3px 0 0 #00ae94;
    background-color: #00cdae;
  }
  
  /* arrows */
  .btn span.arrow-left, .btn span.arrow-right {
    position: absolute;
  	width: 0; 
  	height: 0; 
  	border-top: 25px solid transparent;
  	border-bottom: 25px solid transparent;
  	
    -webkit-transition: all .15s;
    -transition: all .15s;
    -webkit-transition-property: left, right;
    transition-property: left, right;
    
  }

  .btn.left span.arrow-left {
    right: 0;
    -webkit-box-shadow: 10px 0 0 0 #00cdae,
                10px 3px 0 0 #00ae94;
    box-shadow: 10px 0 0 0 #00cdae,
                10px 3px 0 0 #00ae94;
  	border-right:10px solid #00cdae;
  }
  .btn.right span.arrow-left {
    right: 0;
    -webkit-box-shadow: 10px 0 0 0 #00967f,
                10px 3px 0 0 #007261;
    box-shadow: 10px 0 0 0 #00967f,
                10px 3px 0 0 #007261;
  	border-right:10px solid #00967f;
  }

  .btn.left span.arrow-right {
    left: 0;
    -webkit-box-shadow: -10px 0 0 0 #00967f,
                -10px 3px 0 0 #007261;
    box-shadow: -10px 0 0 0 #00967f,
                -10px 3px 0 0 #007261;
  	border-left:10px solid #00967f;
  }
  .btn.right span.arrow-right {
    left: 0;
    -webkit-box-shadow: -10px 0 0 0 #00cdae,
                -10px 3px 0 0 #00ae94;
    box-shadow: -10px 0 0 0 #00cdae,
                -10px 3px 0 0 #00ae94;
  	border-left:10px solid #00cdae;
  }
  
  /* Slants */
  .btn span.slant-left, .btn span.slant-right {
    position: absolute;
  	width: 0; 
  	height: 0; 
  	border-top: 0 solid transparent;
  	border-bottom: 50px solid transparent;
  	
    -webkit-transition: all .15s;
    -transition: all .15s;
    -webkit-transition-property: left, right;
    transition-property: left, right;
    
  }
  
  .btn.left span.slant-right {
    left: 0;
    -webkit-box-shadow: -10px 0 0 0 #00967f,
                -10px 3px 0 0 #007261;
    box-shadow: -10px 0 0 0 #00967f,
                -10px 3px 0 0 #007261;
  	border-left:10px solid #00967f;
  }
  .btn.right span.slant-right {
    left: 0;
    -webkit-box-shadow: -10px 0 0 0 #00cdae,
                -10px 3px 0 0 #00ae94;
    box-shadow: -10px 0 0 0 #00cdae,
                -10px 3px 0 0 #00ae94;
  	border-left: 10px solid #00cdae;
  }
  .btn.left span.slant-left {
    right: 0;
    -webkit-box-shadow: 10px 0 0 0 #00cdae,
                10px 3px 0 0 #00ae94;
    box-shadow: 10px 0 0 0 #00cdae,
                10px 3px 0 0 #00ae94;
  	border-right: 10px solid #00cdae;
  }
  .btn.right span.slant-left {
    right: 0;
    -webkit-box-shadow: 10px 0 0 0 #00967f,
                10px 3px 0 0 #007261;
    box-shadow: 10px 0 0 0 #00967f,
                10px 3px 0 0 #007261;
  	border-right: 10px solid #00967f;
  }
  
  .btn:active,
  .btn.active {
    height: 51px;
  }
    
  .btn:hover {
    
  }
    .btn:hover span.arrow-left {
      right: 10px;
    }
    .btn:hover span.arrow-right {
      left: 10px;
    }
    .btn:hover span.slant-left {
      right: 10px;
    }
    .btn:hover span.slant-right {
      left: 10px;
    }

The post CSS Animated Buttons With Icons appeared first on webdesigncrowd.com.


Viewing all articles
Browse latest Browse all 31

Trending Articles