How to apply multiple transform properties to an element using CSS?
One of the most powerful features of CSS is the ability to apply multiple transforms to an element, which can be used to create stunning visual effects and animations. In this article, we'll discuss how to apply multiple transform properties to an element using CSS, and provide examples of how to leverage this technique to improve your website's user experience.
We'll cover the basic syntax of transform properties, as well as more advanced techniques such as nesting transforms and using multiple transforms to create complex animations. Whether you are a beginner or an experienced web developer, this article will provide you with the knowledge and skills you need to take your CSS skills to the next level.
CSS Transform Property
CSS transform Properties enable developers to apply various transformations to HTML elements, such as scaling, rotation, skew, and translation. transform The properties are very versatile and allow for creative and dynamic design on web pages.
grammar
element{ transform: rotate() | scale() | skew() | translate(); }
Example
Let’s take an example of rotating an HTML element using the transform attribute. To rotate an element, we use the rotate function, which takes an angle value (in degrees) as its argument. Here is an example -
<html> <div class="rotate"> Column </div> <style> .rotate { background-color: orange; margin: 30px; width: 70px; height: 90px; transform: rotate(45deg); } </style> </html>
Apply two transform properties on an element
To apply multiple transform properties to an element, you simply include each transform property you want to apply in the same CSS rule, separated by spaces.
Example
For example, let's say you want to apply a rotation and scaling effect to an element. Let's take a look.
<html> <head> <style> .rotate { background-color: orange; margin: 50px; width: 70px; height: 60px; text-align: center; letter-spacing: 1px; } .rotate:hover { transform: rotate(65deg) scale(1.5); } </style> </head> <body> <h1>CSS Transform Properties</h1> <h3>Given below is a div element which is rotated by 65deg as well as scaled up by 1.5 on hovering.</h3> <div class="rotate"> Column </div> </body> </html>
In the above example, the .rotate selector locates the element to be transformed, and the transform attribute contains both rotate and scale Functions are separated by spaces.
Therotate function applies a 65-degree rotation to the element, while the scale function scales the element to 150% of its original size. Transform properties are applied when you hover over the element.
Apply multiple transform properties to elements
The shorthand syntax allows you to include multiple transformation functions in a single transform attribute by separating them with commas.
Example
This is an example. Here, the rotate function applies a 65-degree rotation to the element, while the scale function scales the element to 150% of its original size. translate The function moves the element 40 pixels to the right and 35 pixels down from its original position. Transform properties are applied when you hover over the element.
<html> <head> <style> .rotate { background-color: yellow; margin-left: 80px; width: 70px; height: 60px; text-align: center; letter-spacing: 1px; } .rotate:hover { transform: rotate(65deg) scale(1.5) translate(40px, 35px); } </style> </head> <body> <h1>CSS Transform Properties</h1> <h3>Given below is a div element which is rotated by 65deg as well as scaled up 150 times on hovering. Also, it translates by 40px and 35px.</h3> <div class="rotate"> Column </div> </body> </html>
Use multiple transformations
Let's create an animation that flips the card over to show its back when clicked. You can achieve this by using multiple transforms in CSS along with some keyframe animation.
Example
<html> <head> <style> .card { width: 200px; height: 300px; position: relative; transform-style: preserve-3d; transition: all 0.6s ease-in-out; } .card .front { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; background-color: #FFFDD0; } .card .back { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; background-color: #FFDEAD; transform: rotateY(180deg); } .card:hover { transform: rotateY(180deg); } .card:active { transform: rotateY(180deg) scale(0.8); } @keyframes flip { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } } @keyframes shrink { from { transform: rotateY(180deg) scale(1); } to { transform: rotateY(180deg) scale(0.8); } } .card:active { animation: flip 0.6s ease-in-out, shrink 0.6s ease-in-out; } </style> </head> <body> <div class="card"> <div class="front"> <h2> Front Side </h2> <p> Hello World!! This is the front side of the card. Hover on me to see the back side. </p> </div> <div class="back"> <h2> Back Side </h2> <p> Hello World!! This is the back side of the card. </p> </div> </div> </body> </html>
When the front card is hovered, we can see the back of the card.
Card is a container containing two child elements, .front and .back, which represent the front and back of the card respectively. The .front and .back elements are absolutely positioned inside the .card container, and their backface-visibility property is set to hidden to prevent them from being visible when facing the user.
When a card is hovered over, it will flip over to reveal its back. When you click on a card, it flips and shrinks to 80% of its original size.
Flip animation will cause the card to rotate 180 degrees in 0.6 seconds, shrink animation will cause the card to shrink to 80% of its original size in the same time period.
When the card is clicked, both animations are applied simultaneously, creating a complex animation that includes multiple transforms and transitions between the front and back faces.
in conclusion
In this article, we learned that applying multiple transform properties using CSS is a simple way to create complex animations and effects of HTML elements. Using the transform attribute, you can apply various transformations, such as scaling, rotation, tilt, and translation, to any HTML element on your web page. By combining multiple transform properties, you can create more dynamic and attractive designs.
The above is the detailed content of How to apply multiple transform properties to an element using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
