Adding a three-dimensional effect by rotating an image with CSS

Hey there, I'm attempting to incorporate both rotation animation and perspective in CSS.

It seems that I can only get one or the other to work, as shown below:

.vinyl {
    width: 200px;
    display: block;
    margin: auto;
    opacity: 0.8;
    transform: rotate3d(1,0,0,45deg)
}

Or like this:

.vinyl {
    width: 200px;
    display: block;
    margin: auto;
    opacity: 0.8;
/*     transform: rotate3d(1,0,0,45deg); */
    animation: rotation 2s infinite linear; 
}

How can I combine both rotation animation and perspective so that it appears like the image is rotating with a perspective view?

You can find the full code here.

.vinyl {
    width: 200px;
    display: block;
    margin: auto;
    opacity: 0.8;
/*     transform: rotate3d(1,0,0,45deg); */
    animation: rotation 2s infinite linear; 
}

.container{
transform-style: preserve-3d;
perspective: 350px;
}

@keyframes rotation {
    from {
        -webkit-transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(359deg);
    }
}
<div class="container">
<img class = 'vinyl' src="https://picsum.photos/seed/picsum/200/300" alt="">
</div>

Answer №1

Continue utilizing the 3D transformation within your animation:

.vinyl {
  width: 200px;
  display: block;
  margin: auto;
  opacity: 0.8;
  animation: rotation 2s infinite linear;
}

.container {
  transform-style: preserve-3d;
  perspective: 350px;
}

@keyframes rotation {
  from {
    transform: rotate3d(1, 0, 0, 45deg) rotate(0);
  }
  to {
    transform: rotate3d(1, 0, 0, 45deg) rotate(360deg);
  }
}
<div class="container">
  <img class='vinyl' src="https://picsum.photos/seed/picsum/200/300" alt="">
</div>

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

Tips for defining types for specific CSS properties in TypeScript, such as variables

Perhaps there are already solutions out there, and I appreciate it if you can share a link to an existing thread. Nevertheless... In React, when I use the style prop, I receive good autocompletion and validation features like this example: https://i.sstat ...

What is the best way to center the content vertically within flex items?

I am working with a flexbox header that has two child flex items, each with their own children. Is there a way to change the vertical alignment of the flex items so that their children are aligned at the bottom? div.flexbox { display: flex; align ...

Converting Rich Text Format (RTF) Data to HTML: A Step-by

I have information stored in RTF Format within an MS Access Database. The format is as follows: {\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\f ...

Enhancing JSON Objects in AngularJS with Custom Properties and Calculations

Hello, I'm still getting the hang of angularjs and could use some guidance. I have a Rest service that provides data on saleItems when a get request is made, as shown below: saleItems = [ { "id": 236, "variant": "Oval Holder", "mrp": "6 ...

Ways to minimize the size of Nextjs Static HTML Export page on disk

While utilizing Nextjs Static HTML Export, I've noticed that each page (consisting solely of HTML code) is being generated with a file size of over 100kb on disk. Are there any methods available to decrease the page size on disk? ...

Display a division upon clicking a button using AngularJS and HTML

Looking to implement a functionality in my HTML page using angularJS. I am currently learning angularJs and experimenting with a feature where clicking on a button will display a specific div (EmployeeInfoDiv) on the webpage. The idea is to fill out some t ...

What is the method for extracting the initial H1 tag from a URL?

As I get ready for an upcoming interview, I am reviewing questions from a website. One question stumping me is: how can I write a function to extract the value of the first H1 element from a specified URL? The possible scenarios include: An H1 elemen ...

The divs descend one after another with no problems related to margins or padding

Having some trouble creating a unique WordPress theme with Bootstrap3. I can't seem to get my divs to behave properly and I've tried everything from display: inline, vertical-align: top, floats, clears, etc... but nothing seems to work. Here is ...

What is the best way to create more space between written text and the line beneath it?

Here's how my bootstrap navbar appears: https://i.sstatic.net/ZPe9c.png As I hover over each menu option, there is an animated underline that displays like so: https://i.sstatic.net/JWKWy.png Is there a way to widen the space between the text and it ...

Is there a way to ensure that the cards remain securely within the confines of the background image at

Struggling to keep the cards neatly contained within the background image regardless of screen size. Here's my code snippet: {% block content %} <style> .custom-skills-section { background: url('{{ background_image ...

Creating an input that can increment or decrement within a dropdown menu - instructions

I am currently working on creating a dropdown with decrement/increment buttons, similar to the one shown in the image below: https://i.sstatic.net/nTC9Z.jpg Here is the code I have so far: <div class="dropdown"> <button class="btn border-0 dro ...

Concealing a field when the PHP post is devoid of content

On page1.php, there is a form that, upon submission, redirects to page2.php where the selected information is summarized. The code snippet below on page2.php retrieves this information. I am attempting to dynamically hide certain rows if the PHP post is e ...

Strategies for avoiding text wrapping in Bootstrap labels on Firefox

Within my panel and panel-body, there are multiple span elements that display dynamically. These spans behave perfectly in Safari and Chrome, wrapping to the next line when needed. However, in Firefox, they overflow strangely. Here are the comparisons: Ch ...

Changing Location of Carousel in Bootstrap

Recently, I have been working with Bootstrap and have encountered a problem with the carousel. I have placed carousel images below my navbar, but there seems to be a gap between the navbar and the carousel image. I want the image to be right below the navb ...

Looking for a Selenium script to target the following elements with either CSS or XPath selectors

Here is some HTML code snippet: <div class="top_message_container"> <div style="margin-left: 544.5px; top: -100px;" class="top_msg_div"> point deleted</div> </div> I need assistance in writing Selenium code using Java. This ...

Implementing a delay in a CSS menu design while still ensuring compatibility with browsers that do not support JavaScript

I currently have a three-tiered menu that relies on :hover and is controlled by css alone. I am now looking to introduce a slight delay to the hovers, which means transitioning my css :hovers to a .hover class and incorporating jQuery. My concern is whet ...

Comparing DOM Creation in PHP and JavaScript

My website currently does not have any ajax requests, and here is a simplified version of my code: class all_posts { public function index($id){ $statement = $db->prepare("SELECT * FROM mytable WHERE id = :id"); $statement->exe ...

the specified container cannot be found

In my project, I am using a repeater. When a user adds a new document, I want to highlight the new documents similar to how Gmail bolds new emails in an account. This way, it will be easier for users to identify the newly added records. Can anyone suggest ...

Firefox Flaw: Animation Issues with CSS

My Website has a CSS animation that creates a hover effect on a button. While the animation looks good in Chrome and IE, I encountered an issue with Firefox. https://i.sstatic.net/y2po7.png Some white pieces are still visible after hovering. Here is th ...

Choppy Animation in Bootstrap 4 Collapsible Card Design

Creating a card using Bootstrap 4 with a .card-header and .card-block: <div class="card"> <div class="card-header"> <a data-toggle="collapse" href="#test-block" aria-expanded="true" aria-controls="test-block"> car ...