Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML5
Tip/Trick

Create Attractive Button Step by Step

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
25 Aug 2013CPOL1 min read 21.8K   199   3   3
Create an attractive Button using CSS3 -Step by Step

In this trick, we are going to create an attractive Button and give it a feel like a 3D button.

Let's Start

HTML Document Structure

HTML
<div class="box">
	<a href="#" class="red">Click Here</a>
</div> 

Here I create a div container having a link (named: Click Here).

CSS

CSS
.box
{
background-color:#e1e1e6;
width:400px;
height:100px;
border:1px solid black;
border-radius:5px;
}

Here I set .box background color, etc. This step is not so important. I only created a box here inside which I have to create a button.

Preview

Image 1

CSS

CSS
.red
{
position:relative;
top:36px;
left:35%;
text-decoration:none;
color:#fff;
background:#cb2727;
text-align:center;
padding:20px 30px;
width:115px;
border-radius:5px;
border:solid 1px #ec3838;
transition: all 0.1s;
-webkit-box-shadow: 0px 9px 0px #a81515;/*for opera and safari*/
-moz-box-shadow: 0px 9px 0px #a81515;/*for mozilla*/
-o-box-shadow: 0px 9px 0px #a81515;/*for opera*/
-ms-box-shadow: 0px 9px 0px #a81515;/*for I.E.*/ }  

Firstly, I set Position of button inside my div container (.box).

I set text-decoration to none so that link underline is removed. After that, I adjusted color and background-color. Then, I set text-align and padding. The important step here is transition and box-shadow.

  • CSS3 transitions are effects that let an element gradually change from one style to another.

Preview

Image 2

CSS

CSS
.red:active 
{
-webkit-box-shadow: 0px 2px 0px #a81515;
-moz-box-shadow: 0px 2px 0px #a81515; 
-o-box-shadow: 0px 2px 0px #a81515; 
-ms-box-shadow: 0px 2px 0px #a81515; 
position:relative; 
top:43px; 
}

The :active selector is used to select and style the active link. A link becomes active when you click on it.

The main trick behind this button’s working is that decrease box-shadow and move the position slightly down so that appears pressing down.

Preview

image3

Browser Support

Image 4

How It Looks During Clicking

Image 5

That's all. Hope you like it.

Thanks.

My Other Post (Tips and Tricks)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
India India

Comments and Discussions

 
Questionvery Long to code it Pin
Mayank2yk25-Aug-13 11:24
Mayank2yk25-Aug-13 11:24 
AnswerRe: very Long to code it Pin
Anoop Kr Sharma25-Aug-13 18:15
professionalAnoop Kr Sharma25-Aug-13 18:15 
GeneralRe: very Long to code it Pin
Mayank2yk27-Aug-13 19:14
Mayank2yk27-Aug-13 19:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.