Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Creating a Button using HTML5 and CSS3
WhatsApp
Anoop Kumar Sharma
5y
7.9k
0
0
100
Article
Buttonexample.zip
Introduction
In this article, we are going to create a button and give it feeling like 3D using HTML5 and CSS3.
Starting from HTML Document
<body>
<a href=
"#"
class
=
"red"
>Click Here</a>
</body>
Preview
Styling it using CSS
.box {
background-color: #e1e1e6;
width: 400px;
height: 100px;
border: 1px solid black;
border-radius: 5px;
}
/*for styling box inside which button is placed*/
.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.*/
}
Here we set text-decoration to none so that link underline removed. After that adjusted color and background-color. Then set text-align and padding. Important Step here is transition and box-shadow.
CSS3 transitions are effects that let an element gradually change from one style to another.
Preview
Final step (Adding CSS for :active)
The : active selector is used to select and style the active link. A link becomes active when you click on it.
.red:active {
-webkit-box-shadow: 0px 2px 0px #a81515;
position: relative;
top: 43px;
}
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 (working)
That's all.
Button using HTML5
CSS3
HTML 5
HTML Document
Up Next
Ebook Download
View all
Frontend Developer Interview Questions and Answers
Read by 938 people
Download Now!
Learn
View all
Membership not found