What can be done to extend the duration of a button click's `:active` animation?

Here is the requirement. When a user clicks on the button, I want to change its box-shadow to provide visual feedback of their click. In an attempt to achieve this, I implemented the following solution:

button {
  box-shadow: inset 0 0 4px 4px rgba(0, 0, 0, 0);
  transition: box-shadow 0.4s;
}

button:active {
  box-shadow: inset 0 0 4px 4px rgba(173, 216, 230, 1)
}
<button>Click me</button>

Despite setting the transition style value to 0.4 seconds, the animation does not execute as intended when the button is clicked. It appears that the button press duration may be too short for the effect to fully display.

Could someone suggest a solution to ensure the box-shadow change lasts for the intended 0.4 seconds, providing users with clear feedback on their clicks?

Access the codepen link here: https://codepen.io/AnirudhMS/pen/MWXWNNz (set the transition-duration to 1s for better visualization)

Answer №1

I ran your code and it executed exactly as intended. Please share the snippet of your actual code.

If you are implementing it within a framework, make sure to include the important tag for it to work properly as demonstrated below:

button:active {
  box-shadow: inset 0 0 4px 4px rgba(173, 216, 230, 1) !important;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unsure about the erratic actions of my JavaScript code

My current challenge involves a function that aims to return a global variable as a String object, containing the contents of a local text file. As it stands, this function is returning an empty String. function fetchWords() { var fileRequest = new XM ...

Embed an image within the email's content

Can someone provide guidance on how to insert an image in the email body when the user clicks on the send button? I am currently using PHP mail for this task. ...

Having difficulty deleting a checkbox element using JavaScript

My goal is to have a feature where users can effortlessly add or remove checkbox div elements as needed. The code I have written successfully adds and resets checkboxes, but I am encountering an issue when trying to remove them. I am struggling to identif ...

Unable to locate scripts.js file within the console

I am completely new to jquery and programming in general. I recently tried moving my javascript code to a separate file from the html for organization purposes. Initially, I tested it in my html by adding an alert to see if it was working properly. However ...

Generating a unique element with a specified identification number through JavaScript

Every time the button is clicked, I want to generate a new element with specific id names. Specifically, I am building a form that includes: <h2>Ownership Structure</h2> <div class="form-outline mb-4"> <input type="text" id="ownerNam ...

CSS animations do not seem to work properly on IOS devices

I have implemented the following CSS animations, which work perfectly on desktop browsers even when the window is resized. body { width: 100%; height: 100%; padding: 0; margin: 0; background-color: #0e1624; overflow-y: hidden; o ...

Function does not get triggered by span element within a lightbox

I have recently included a CodePen demonstration My goal is to have the lightbox close upon clicking the close button. The current issue I am facing is that the close function is only triggered when clicking on the background. I seem to be missing someth ...

Personalized search bar and adaptable grid layout

Recently stumbled upon an interesting article about creating a search bar in Photoshop, you can find it here. I am now trying to figure out how to handle background images inside a responsive grid. Can anyone guide me on how to create a similar search bar ...

HTML text has been partly processed

When Xml is parsed using a SAX Parser, there is one specific tag called <Panchanga> which contains HTML contents. The structure of the tag is as follows: <Panchanga><table style='font-size:14px;'> <tr> <td ><img ...

When using Bootstrap with fullcalendar, the tooltips may not display properly

Currently, I am immersed in a confidential Codeigniter project where my goal is to showcase various events in the view utilizing fullcalendar. While progress has been made, I aspire to exhibit more than just the event's name and time; additional deta ...

Why is it that the form does not fully appear when the screen is being resized with absolute display?

Utilizing bootstrap columns, I have a form that is set to display: absolute. However, when the screen size is reduced, the form does not appear completely as seen in this image. How can I ensure that the form appears entirely as shown in the desired resul ...

What is the best way to adjust the padding within a mat-expansion-panel-body?

I recently created an expansion panel that is working well, but I am having trouble removing a padding from the subpanel section. Despite my efforts, I haven't been able to find a suitable solution. Here's a link to the panel image: https://i.ss ...

The challenge of using CSS Flexbox to position the logo with a margin-top

While learning flexbox, I encountered a challenge. I aim to center align h1, p, and button elements, with the logo positioned at the top margin-top of 1em. Essentially, I want the h1, p, and button to be centered, while the logo is positioned at the top wi ...

Load HTML content dynamically based on the output of a PHP script

I am attempting to display the output of a PHP file in an HTML div. I have used jQuery's ($('div').load(url_here)) method and it is functioning correctly. However, the code of my PHP file is as follows: <?php for( $i = 0 ; $i < 10 ; $ ...

What is preventing CSS from recognizing the ~ symbol in relative links on my main page?

Currently, I am developing a web interface using ASP.NET and XHTML 1.0 Transitional doctype. The issue arose when attempting to switch from a real absolute path for the CSS link in the header to tilde notation on a website with a master page setup. The o ...

Unable to define attributes of a non-existent element (specifically 'innerHTML') within a Vanilla JavaScript component

Currently, I'm developing a Vanilla JS Component and encountering a challenge with utilizing the innerHTML() function to modify the text within a specific ID in the render() HTML code. The problem at hand is the Cannot set properties of null (setting ...

What is the method to replace the default font family in Bootstrap?

Adding my own unique style with CSS @font-face { font-family: 'CustomFont'; src: url(./fonts/custom/CustomFont.otf); } h4.CustomFont-style { font-family: 'CustomFont', sans-serif !important ; } Using the custom fo ...

Seeking out the clientside control within the code-behind - what's the best approach

Having trouble accessing a table located in the content page from my codebehind. I am attempting to convert the content to an xml file but the code Table tbSelectedColumns = Master.FindControl("ContentPlaceHolder1").FindControl("selectedColumns") as Ta ...

Fancybox2 does not have a scrollbar feature, but you can customize the size

I've been struggling to hide the scrollbar in fancybox. I attempted the solution provided in this link but unfortunately, it did not work for me. The specific page I am working on is My goal is to have a fixed size and no scrollbar visible when fan ...

Switching from 'click' to 'hover' will make the dropdown menu more accessible for keyboard users

I'm currently updating an existing dropdown menu that meets WCAG standards but I need to tweak the functionality so that it activates on hover instead of click. Below is the code snippet: $(document).ready(function() { $('.has-submenu'). ...