Animate a CSS3 button to shift from the right to the left upon hover

I'm attempting to recreate the button effect seen on the right side of this website.

Starting position :

https://i.sstatic.net/TON94.jpg

End position after animation :

https://i.sstatic.net/UhrZ3.jpg

Here is my HTML code :

<div id="btnFeedbackHome">
            <div><img src="img/home_feedback.png" id="feedbackImgHomeBtn" /></div>
            <p>Ideas & feedback</p>
        </div>

And CSS :

#btnFeedbackHome {
    width: 180px;
    height: 45px;
    position: absolute;
    top: 320px;
    right: 0;
    background-color: #35BDCF;
    cursor: pointer;
}

#btnFeedbackHome p{
    color: white;
    font-weight: 600;
    position: absolute;
    top: 1px;
    right: 8px;
    font-size: 14px;
}

#btnFeedbackHome div{
    width: 45px;
    background-color: #2A97A6;
    height: 45px;
}

#feedbackImgHomeBtn {
    margin-top: 9px;
    margin-left: 7px;
}

Currently, my code displays the end position but I am unsure how to achieve the same transformation effect on my div.

Can anyone assist me with this?

Answer №1

It seems like this solution may fit your needs. If you have any further questions, please don't hesitate to reach out.

body
{
    overflow-x:hidden;
}
#btnFeedbackHome {
    width: 180px;
    height: 45px;
    position: absolute;
    top: 320px;
    right: -135px;
    transition:all 0.5s ease-in-out;
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    background-color: #35BDCF;
    cursor: pointer;
}

#btnFeedbackHome p{
    color: white;
    font-weight: 600;
    position: absolute;
    top: 1px;
    right: 8px;
    font-size: 14px;
}

#btnFeedbackHome div{
    width: 45px;
    background-color: #2A97A6;
    height: 45px;
}

#feedbackImgHomeBtn {
    margin-top: 9px;
    margin-left: 7px;
}
#btnFeedbackHome:hover
{
    right: 0px;
}
<div id="btnFeedbackHome">
            <div><img src="img/home_feedback.png" id="feedbackImgHomeBtn" /></div>
            <p>Ideas & feedback</p>
        </div>

Answer №2

To achieve this effect, you can utilize a simple CSS transition on the element. I have put together a JSFiddle which enhances your example and demonstrates how this can be done without using any JavaScript, simply by adding a hover to the main container. Check it out here: http://jsfiddle.net/cudome3h/1/

If you follow the same steps as before but adjust the CSS code as shown below, you will achieve a similar result:

#btnFeedbackHome {
    width: 180px;
    height: 45px;
    position: absolute;
    top: 320px;
    right: -140px;
    background-color: #35BDCF;
    cursor: pointer;
    -webkit-transition: 0.5s ease-in-out;
    -moz-transition: 0.5s ease-in-out;
    -o-transition: 0.5s ease-in-out;
    transition: 0.5s ease-in-out;
}

#btnFeedbackHome:hover {
    right: 0;
}

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

Confirming whether the digit entered in jQuery is a number

My website has a user input field where numbers are expected to be entered. I wanted to find a convenient way to validate the input using jQuery. After some research, I discovered jQuery's built-in function called isDigit. This handy function allows ...

Set a variable to contain a specific scope in JavaScript

I'm struggling to pass user input from a text box stored in $scope to a firebase query. Here's the code I have so far: $scope.array = []; $scope.addListItem = function(quote){ $scope.array.unshift(quote); console.log(quote) this.customQuote = ...

What is the best way to utilize CSS 'ids' with server controls in ASP.NET?

I have a dilemma with my designer-created stylesheet that heavily relies on ids. For example: <div id="globalheader"> <ul id="globalnav">.... Here is the CSS: #globalheader { width: 715px; height: 100px; margin: 18px auto; position: absolute ...

CSS Menu Expansion Error in Just Two Lines

My CSS-only menu is causing some trouble by expanding to three lines whenever a submenu option on the first line is clicked. The issue only occurs with options in the middle, as it shifts everything out of place and onto another line. Expected behavior: ...

The placement of an element is determined by its size and proportions

I'm experiencing some issues with avatars on my website. When the avatar size is set to 35x35 pixels, everything works fine. However, problems arise when the dimensions exceed 35x35 pixels. I suspect that the problem is related to the "position: abso ...

The button works properly in JSFiddle, however, it is not able to clear the ordered list in the

DEMO Creating a script that captures mouse click coordinates and appends them to a list. The functionality works, except for an issue with the clear button not working properly. After making corrections in jsfiddle, the script functions correctly. Howeve ...

Is there a way to adjust the position of ::before elements without affecting the border placement?

I'm struggling with an element that has a CSS style ::before to display an arrow-up inside a black circle. Check out the code here The issue I'm facing is that the character \25b2 isn't centered vertically within the circle. Adjustin ...

Calculating the upcoming multiplier values for spacers in the Bootstrap 4 framework

Bootstrap is equipped with a range of 0-5 spacers and multiplier values between 0.25 to 3. If the goal is to incorporate spacers up to 15, what should the corresponding multiplier values be? Observing a sequence where each number is twice as much as the p ...

Overflow issue with Bootstrap 4 cards on small screens

When working on my application, I find myself using the bootcard .card class quite frequently. However, I've noticed that when switching to mobile view, there is a significant overflow issue that causes a display bug and shifts my entire page out of ...

Tips for verifying the input field with specific requirements in Angular 6

There is an input field that needs to validate text based on certain logic conditions: No spaces should be allowed in the formula. The operators (and,or) must be lowercase and enclosed in curly brackets {}. The number of opening '(&apos ...

Changing an array into an object in JavaScript without rearranging the keys

I have a collection { 1: {id: 1, first: 1, last: 5} 2: {id: 2, first: 6, last: 10} 3: {id: 3, first: 11, last: 15} } My goal is to reverse the order of items without rearranging the keys so that it looks like this: { 1: {id: 3, first: 11, last: 15} 2: { ...

What is the best method for incorporating meta data, titles, and other information at dynamic pages using Node.js and Express?

I am currently exploring methods to efficiently pass data to the html head of my project. I require a custom title, meta description, and other elements for each page within my website. Upon initial thought, one method that comes to mind is passing the da ...

Having trouble with Rails4 assets when implementing a straightforward slider with Bootstrap?

I've been struggling to implement a basic range slider (1-10) in a form using the 'bootstrap-slider-rails' gem. I've spent nearly 4 hours on it and still can't seem to get it working properly. The JS and CSS files are loading fine, ...

Executing a JavaScript script from a C# script: A step-by-step guide

Greetings all! I am currently engrossed in a school project that requires me to populate a paragraph element with data from a table in my database. Initially, I attempted to achieve this task using JavaScript, but due to the connection script being in C#, ...

Tips on populating the gap between dual cylinder meshes in Three.js

I'm working on a code that creates cylinders using a series of 3D vectors, but I'm encountering an issue with unsightly gaps between them: https://i.sstatic.net/E17Gm.png Does anyone have any tips on how to fill in these gaps in the latest vers ...

Adjusting the placement of Bootstrap popovers according to their horizontal position relative to the window's edge?

After extensive research across the vast expanse of the Internet, I stumbled upon this enlightening stackoverflow post Is it possible to change the position of Bootstrap popovers based on screen width?. However, my query remains unresolved, likely due to m ...

Creating dynamic event handlers in JavaScript

Having some trouble with my JavaScript code. I've been given a string in a specific format that I need to convert into a table. Each row of the table should contain a single cell. The format of the string is as follows: Each cell should display some ...

Customize scripts dynamically in Next.js based on the current environment during runtime

I need to dynamically insert a script into the <head> of my application, with the src attribute depending on a runtime environment variable from my hosting server (OpenShift). If process.env.ENVIRONMENT === "test", I want to add <script ...

Retrieve information using server-side rendering

I'm faced with a situation where my page utilizes query parameters to fetch data via SSR. The challenge arises when these query parameters frequently change, triggering a re-fetch of the data using SSR despite there being no client-side data fetching ...

Unable to show information within input field

I am attempting to present the value of my variable in a textBox using Jade, but I am encountering issues. I have tried the following options: value="#{startDate}" value="#{{startDate}}" value="{startDate}" value={{startDate}} I am aware that it is func ...