Skip to main content

CSS Button Click Effect - Animation Idea #10

  • February 1, 2022
  • 5 replies
  • 578 views

gstager
Hero III
Forum|alt.badge.img+7

In this example - I decided to create a custom button that has the effect of being pressed.

It has the look of a momentary push button rather than a persistent one.

To do this we are simply changing the size and position by just a few pixels and adjusting the color and shadow.

CSS Button Press Effect

Here is how I did it.

/* Button Press Effect */
/* This is the CSS for the Branding and Look section */

#myBtn {
  width: 75px;
  height: 25px;
  background-color: #e21836;
  border-radius: 25px;
  position: absolute;
  box-shadow: 3px 3px grey;
  left: 25px;
  top: 25px;
}

#myBtn:active {
  background-color: #9d061f;
  left: 29px;
  top: 29px;
  width: 74px;
  height: 24px;
  box-shadow: none;
}

#myBtn:active p {
  color: #ffffff;
}

Here is the HTML

<!-- This is the HTML for your widget or other page -->

<div>
<div id="myBtn">
<p style="padding-left:7px;">
Press Me</p>
</div>
</div>


<!-- Want to actually add a link to this button? -->
<!-- You can just add the following and change the URL as desired. -->

<div>
<div id="myBtn">
<p style="padding-left:7px;">
<a href="https://community.docebo.com" target="_blank" style="text-decoration:none;">Press Me</a></p>
</div>
</div>

Hopefully this is helpful for someone.

Did this post help you find an answer to your question?

5 replies

Forum|alt.badge.img
  • Novice III
  • 9 replies
  • October 16, 2023

Hi, love this! Trying it out on our site but having difficulty changing the text and aligning it to the middle - any tips?  

 


gstager
Hero III
Forum|alt.badge.img+7
  • Author
  • Hero III
  • 891 replies
  • October 16, 2023

@Kelly - Have you tried adding a line-height to the inline style on the following line of the HTML?

<p style="padding-left:7px;line-height: 150px">

You could start with a line-height value that matches the height of your box and tweak from there for desired look.


Forum|alt.badge.img
  • Novice III
  • 9 replies
  • October 16, 2023

Great - and can you edit the text from the inline style? I would like it Bold and bigger font 


gstager
Hero III
Forum|alt.badge.img+7
  • Author
  • Hero III
  • 891 replies
  • October 16, 2023

Sure - you could do something like this.

<p style="padding-left:7px;line-height:150px; font-size:18px;">

and for bolding - you can just put tags around the specific text you want bolded.

Go ahead and click <b>Here</b>


Forum|alt.badge.img
  • Novice III
  • 9 replies
  • October 16, 2023

Thanks so much :) this looks fab!! 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings