Transition smoothly with a gradual fade-out effect

I implemented a hover effect on my button with the intention of making the button background transparent gradually when hovered over. However, I am encountering difficulties in achieving the desired transparency...

I opted for ease-in as the transition direction.

Here is the code snippet;

<div class="container">
<button class="btn-1">Get in Touch</button>
</div>

CSS;

.container{
   display: flex;
   flex-direction: row;
   justify-content: center;
   align-items: center;
   text-align: center;
 }

.btn-1{
   width: 300px;
   height: 100px;
   border: none;
   color: white;
   background-color: rgb(25, 62, 148);
   border-radius: 4px;
   box-shadow: inset 0 0 0 0 rgba(0, 0, 0, 0);
   transition: ease-in 0.3s;
   font-size: 2rem;
   outline: none;
 }

 .btn-1:hover{
    box-shadow: inset 300px 0 0 0 rgba(0, 0, 0, 0);
 }

Answer №1

When using the transition property, you need to specify the property-name that will be changed when the event is triggered as the first parameter. I have revised the code for better clarity and also included comments for explanation.

In the example, I have included all, which means that transitions will be applied to all properties that are being altered. It's important to note that transitions only affect properties that are quantitative and can be measured.

.container{
   display: flex;
   flex-direction: row;
   justify-content: center;
   align-items: center;
   text-align: center;
 }

.btn-1{
   width: 300px;
   height: 100px;
   border: none;
   color: white;
   background-color: rgb(25, 62, 148);
   border-radius: 4px;
   box-shadow: inset 0 0 0 0 rgba(0, 0, 0, 0);
   transition: all ease-in 0.3s; /* Specify the property for which the transition should apply. Here, 'all' is used to apply to all properties, but you can use a specific property name (e.g., background-color) */
   font-size: 2rem;
   outline: none;
 }

 .btn-1:hover{
    background-color: rgb(25, 6, 18); /* Update the property that needs to change on hover */
 }
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

</head>
<body>

<div class="container">
<button class="btn-1">Get in Touch</button>
</div>

</body>
</html>

The transition property specifies which property should undergo a transformation.

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

optimal application of css with jquery

I have a question about using jQuery to set the padding of a class or id. I am able to successfully change the height of an element with this code: $('.menu').css({ height: '90px' }); But now, I need to apply a specific CSS rule in jQ ...

What is the best way to reduce the font size on a

I've been applying the following CSS: .text_style3{ font:normal 8px Helvetica; color:#f7922c; } I'm trying to decrease the size further, but anything below 10px doesn't seem to work. I've attempted using 7px, 6px, 5px, etc., w ...

Steps for implementing a reset button in a JavaScript slot machine game

I need assistance with implementing a reset button for my slot machine game prototype written in JS. I attempted to create a playAgain function to restart the game by calling the main game function, but it's not working as expected. Do I need to pass ...

The distance from the edge of my tilted svg icon to the svg artboard

I'm currently working on developing a basic web icon system using SVG sprites. However, I have encountered a spacing issue in my code around one specific icon (between the Smash Magazine icon and the red border). I am trying to figure out how to remov ...

What is preventing us from setting a child's width and height to match that of the parent element?

Parent element is a div with a width of 300px and a height of 40px, containing a child input. In the following code snippet: myinput = document.getElementById("e2"); myinput.style.cssText ='width:100%;height:100%;padding:0px;margin:0px;' div{ ...

Leveraging the @font-face feature along with fonts sourced from fontsquirrel

As I embark on creating my very first website, I find myself delving into the world of fonts from Font Squirrel. However, a challenge arises as I realize that not all the fonts I downloaded from the site are easy to use. The real struggle comes when deal ...

Arrange the HTML elements in a line, one following the next

I need assistance with aligning two dropdown lists in the jsbin provided. How can I position them one after the other, center them on the page, and ensure there is enough space between the two elements without manually adding spaces using   In additi ...

What steps can I take to mimic a pen-like behavior for my cursor on my sketching website project?

My goal is to create a 16x16 grid with a white background, where each grid item changes color when the mouse is pressed and moved over it, similar to paint. I have written a script to achieve this: let gridContainer = document.getElementById('grid-con ...

Outlook causing images to shift with unexpected 1px padding on left and top in HTML email design with PNGs and background color

Is there a way to place a transparent PNG* over a background color for creating a series of emails with just the background color being changed? I have noticed that Outlook** adds a 1px padding / margin to the left and top of the image, which allows the ba ...

The issue with applying local css links in Bootstrap 3 is not being resolved

I am currently in the process of developing a flat website for my landlord using the Bootstrap 3 framework. However, I'm facing an issue where my navigation bar is only displaying as an unordered list rather than a horizontal bar. The CSS code can be ...

What is the best way to restrict the border to just one element?

I've configured my navigation bar using a list with li elements. To give it a rounded appearance, I applied a border-radius to the background. Now, I'm looking to remove the border-left specifically from the home element. Below are the code snipp ...

Unlock the power of automatic code reloading in Rails with these simple steps

Looking for a way to implement 'hot code reloading' in a development Rails application? Let's say you're working on a Rails project and make changes to a stylesheet. Currently, you have to refresh the page using cmd-r or by clicking th ...

Perform the action when the button is clicked

I'm struggling with finding a solution to this problem. I have an input field and a submit button. My goal is to update the value of a variable to match the value in the input field when the submit button is clicked. Additionally, I need to execute a ...

Issues arise with AJAX authentication request

Currently, I'm working on incorporating a basic login form with an AJAX request that forwards the user to a page for querying my database. Depending on the results, the user is then redirected to the main index page or prompted back to the login form. ...

Conceal a division using CSS based on its data-role attribute

After extensive research, I have yet to find a solution. Let's say there is a div structured like this: div[data-role="form-footer"] What would be the most effective method for hiding it, and can it be done using CSS? I've tried the f ...

If the URL hash matches the ID of a specific div, then take action on the div's child element

Imagine I have the following HTML structure: <div class=".blog-item-holder"> <div id="AAAA"><div class="inner">AAAA</div></div> <div id="BBBB"><div class="inner">BBBB</div></div> <div id="CCCC">& ...

What is preventing my HTML/CSS code from generating a button on the webpage?

There seems to be an issue with the image on my webpage - it's displaying a broken page icon instead of the actual image, even though it was showing fine before. The image name and location have not been changed. I'm also having trouble creating ...

As the browser window is resized, the HTML div is causing the image to be clipped

Having an issue with the dynamic resizing of Divs containing Images in my HTML Table. The Challenge: The Image within a resizable Div gets clipped at the bottom when the height decreases due to window resizing. To view the problem, visit this Example Pag ...

Expanding the height of an image in a multi-select dropdown using CSS

I have an image that is included in all text fields and drop downs like so: However, when it comes to a multiple select drop down box, the image appears differently: I would like the image to display as shown above for multiple select drop downs. I atte ...

Creating a visual that when clicked, reveals an enlarged version at a different location

Is there a way to make an image appear in a different location on the page when it's hovered over? I've searched online but couldn't find a solution using just HTML and CSS. Does anyone know how to achieve this effect? Image not hovered: ht ...