Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css button pressing effect [duplicate]

Tags:

I have a button with a box-shadow that makes it look like it's floating, and I would like to make a pressing effect when I click on it:

Code(CSS):

#startBtn {     font-family: OpenSans;     color: #FFFFFF;     background-color: #00FF7C;     border: 1px solid #00FF7C;     border-radius: 5px;     box-shadow: 0px 5px 0px #00823F; } 

Code(HTML):

<input type="button" id="startBtn" value="Let's begin"> 

Screenshot:

Button

like image 934
Jojo01 Avatar asked Sep 08 '15 14:09

Jojo01


People also ask

How do I create a button press effect in CSS?

We can use CSS transform property to add a pressed effect on the button when it is active. CSS transform property allows us to scale, rotate, move and skew an element.

What is button ripple?

For example, buttons now display a ripple effect when they are touched - this is the default touch feedback animation in Android 5.0. Ripple animation is implemented by the new RippleDrawable class. The ripple effect can be configured to end at the bounds of the view or extend beyond the bounds of the view.


1 Answers

Use :active pseudo class and change the box-shadow vertical offset value. Adjust the top value for the activated element with respect to the relatively positioned input with absolute parent.

.button {    position: absolute;  }  #startBtn {    font-family: OpenSans;    color: #FFFFFF;    background-color: #00FF7C;    border: 1px solid #00FF7C;    border-radius: 5px;    box-shadow: 0px 5px 0px #00823F;    position: relative;    top: 0px;    transition: all ease 0.3s;  }  #startBtn:active {    box-shadow: 0 3px 0 #00823F;    top: 3px;  }
<div class="button">    <input type="button" id="startBtn" value="Let's begin">  </div>
like image 149
m4n0 Avatar answered Sep 22 '22 03:09

m4n0