Tips for moving objects in both the X and Y directions using only CSS transformations

Is it possible to rotate a card simultaneously in the X and Y directions?

I have an image that I would like to rotate in both the X and Y directions!

This code is written in HTML,

<div class="card"></div>

and this is CSS,

.card {
background-image: url("https://i.sstatic.net/FW7wN.png");
height: 100px;
margin: 50px auto;
position: relative;
width: 100px;
-webkit-transition: .5s linear;
-webkit-transform-style: preserve-3d;
}


.card:hover {
-webkit-transform: rotateX(60deg);
}

Visit the Fiddle Project Here

When I try to add the Y transition to the hover effect, it only takes into account the second transition and ignores the first one Like This

 .card:hover {
-webkit-transform: rotateX(60deg);
-webkit-transform: rotateY(60deg);
}

Is there a way to translate that Card both along the X and Y diagonals? Please provide assistance!

Answer №1

To create a dynamic rotation effect, you can utilize rotateX(), rotateY(), or rotateZ() in combination, such as:

.card:hover {
  transform: rotateX(60deg) rotateY(60deg) rotateZ(60deg);
}

Take a peek at the code snippet below for reference:

.card {
    background-image: url("https://i.sstatic.net/FW7wN.png");
    height: 100px;
    margin: 50px auto;
    position: relative;
    width: 100px;
    -webkit-transition: .5s linear;
    -webkit-transform-style: preserve-3d;
}
    
.card:hover {
    -webkit-transform: rotateX(60deg) rotateY(60deg) rotateZ(60deg);
}
<div class="card"></div>

I hope this explanation proves useful!

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

Having trouble getting jQuery Ajax data to work properly on the same PHP page?

I am working with a file called 22.php where both the form and PHP script are located. Issues: https://i.sstatic.net/3vG5N.jpg https://i.sstatic.net/5KXz6.jpg 1) After submitting, the result is displayed below. However, it duplicates the form. 2) Ente ...

The justify-content: space-between property does not work in a nested flex box scenario

I'm currently working on styling a cart in Angular and facing an issue with aligning the price all the way to the right of the cart. I attempted using `space-between` within the outer div, which worked fine, but when applied to the inner div, it doesn ...

Is there a way to upload multiple files using expressjs?

I'm looking for a way to efficiently send multiple files, including an entire directory, so that I can access them in another JavaScript file called from an HTML file. const app = require("express")(); const http = require("http"). ...

Perfecting the Radio Button Selection (because why not?)

Struggling to round the outer corners of three inline squared radio buttons with unique IDs. Need help fixing my CSS syntax - I can get each button to individually round its corners, but not just radio1 and radio3's outer corners. Check out the issue ...

The PHP-based registration process is malfunctioning

Trying to simply register, but I'm encountering an issue where the file is named Login.html/.php instead of just Login.html. Below is my HTML form in Login.html: <!DOCTYPE html> <html> <head> <title>Register/ Login</title&g ...

Guide to configuring a Carousel with a 100% width

https://i.sstatic.net/zYpbd.pngI'm having trouble making my carousel responsive on my webpage. I tried setting its width to 100% within a class, but it doesn't seem to be working. How can I ensure that the carousel's width is 100% and still ...

Certain users are experiencing a white screen when trying to view dynamic HTML5 videos on Firefox

Our header video displays an image first before lazy loading a video in either mp4 or webm format, depending on the user's browser. However, some Firefox users are experiencing issues where the HTML5 video source appears white instead of playing. Int ...

Issue with Angular5: Spinner malfunctioning during initialization of the page

My service emits two events dataLoaded and loadingData. I want to display a GIF image when data is loading and hide it when data is loaded. In the component, I handle both events and update a Boolean variable accordingly. However, on the initial page load, ...

Why are my Chrome Div regions failing to expand to their full width?

I have been searching but couldn't find an answer to my issue, so I apologize if this question has been asked before. I am working on a simple site layout and noticed that two of the div regions do not expand fully in Chrome, however, they do in Firef ...

Tips for organizing content on a webpage by placing heading and paragraph tags side by

I am struggling to align heading and paragraph tags side by side in an inline format. Here is my attempt using bootstrap 4: <div class="col-md-1 text-left"> <span class="d-inline"> <h2> {{ event ...

Center JQuery within the current screen

My implementation of Jquery dialog is as follows: <body> <div id="comments_dialog"> Insert a comment <form> <input type="text" id="search" name="q"> </form> </div> .... </body> dialog = $( "#com ...

AngularJS $timeout function failing to update variable

I'm currently working on implementing a shaking animation for a button when it's clicked and the form fields above it are invalid. This is the snippet of code from the controller: if(valid){.. do valid stuff here ..} else{ console.log(this.sha ...

Experiencing the error message "Unable to access property 'innerHTML' of null" despite initializing the corresponding ID

After doing some research, I discovered that this issue usually arises when the specific div is not loaded yet or simply does not exist. My code is set to loop continuously, ensuring that even if it wasn't fully loaded the first time, it will be by th ...

How come the margin-bottom is displaying as the margin-top?

When I attempt to add margin-bottom on a div inside its parent, it seems to display as the parent's margin-top. Why is that? HTML: <div id="wrapper"> <div id="content"> <div id="box"></div> </div> </d ...

Even after the loading spinner stops and the page appears, there is a 10-second delay where scrolling and clicking buttons are not responsive in the browser

Despite the browser's loading spinner stopping and the initial content of the page appearing ready, all buttons are unresponsive and scrolling is impossible for at least 10 seconds after the spinner stops. This page contains multiple views that are i ...

Achieving horizontal scrolling for tables without using div wrappers

Whenever the width of tables in my articles exceeds the available space in the webpage layout, I wanted to enable horizontal scrolling. Despite trying to accomplish this with CSS alone, I was unsuccessful. As a result, I resorted to enclosing everything i ...

Any ideas on how to present data in a card layout with two columns?

.card { box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s; } .card:hover { box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); } .container { padding: 2px 16px; } .card { width: 50%; heig ...

Are both of my responsive CSS files supposed to be loaded by Chrome as normal behavior?

I am attempting to implement different CSS files for the mobile and desktop versions of my website in the following manner: <link rel="stylesheet" media="screen and (min-width: 768px)" href="home.css" /> <link rel="stylesheet" media="screen and ( ...

Web Page Content Scrambling/Character Exchange

I've encountered a perplexing issue that seems to strike randomly, yet I've managed to replicate the problem on three different desktops. Oddly enough, some other desktops never experience this issue and I'm at a loss as to what could be cau ...

Customize your AutoComplete with MUI styling

Upon taking over a project, I found myself working with material ui for the first time. Here is an excerpt from my code: <FormControl fullWidth> <InputLabel className={className} htmlFor={id} error={error} > ...