JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > CSS >

Applying multiple transformations in CSS

Author:JIYIK Last Updated:2025/04/19 Views:

CSS transforms are a powerful but underutilized way to add animation effects to elements. However, it can be tricky to get the desired results when applying multiple transformations at once; for example, we want elements to transform in sync when they overlap.

This article will explore how to apply multiple transformations in CSS.


Apply multiple transformations by specifying multiple transformation values ​​in CSS

There are many ways to use multiple CSS transitions. We will discuss them in the following sections.

One way to apply multiple CSS transforms is to use the shorthand transform property. This property can take multiple values, separated by spaces.

For example:

transform: rotate(45deg) scale(2);

This line will rotate the element 45 degrees and then double its size.

As another example, if you wanted to rotate an element 30 degrees and then translate it 50 pixels, you would use the following code:

transform: rotate(30deg) translate(50px);

This line can be a valuable technique for creating complex animations and interactions.

Now let's see some examples of multiple transformations. You can use the following code to transform an image.

Sample code:

<!DOCTYPE html>
<html>
    <head>
        <title>Title of the document</title>
        <style>
            body {
                margin: 10px;
            }
            .box {
                background: url("/img/DelftStack/logo.png")
                    no-repeat;
                background-size: cover;
                height: 100px;
                width: 600px;
                border: 2px solid #000000;
                transform: rotate(110deg) translate(45px, -160px);
            }
            h1 {
                color: #000000;
            }
        </style>
    </head>
    <body>
        <h1>
            CSS Multiple transforms
        </h1>
        <strong>
            How to apply multiple transforms in CSS?
        </strong>
        <div class="box"></div>
    </body>
</html>

In the code above, we have used the CSS function transform: rotate(110deg) translate(45px, -160px)to transform the image. This CSS code will rotate the image 110 degrees.

So by using the above code you can apply it to convert any image.


Apply multiple transforms by specifying them in CSS

Another way to use multiple transformations is to specify each transformation individually.

For example:

transform: rotate(45deg);

transform: scale(2);

Applying multiple transforms by specifying multiple transform origins in CSS

You can also change the origin of the transform using the transform-origin property. For example:

transform-origin: 50% 50%;

transform-origin: bottom right;

This changes the origin to the center of the element or the bottom-right corner of the component.


Applying multiple transitions using nested classes in CSS

There is another way to apply CSS transformations. Below is one CSS code, but we will create two nested classes, outer-transform and inner-transform, to apply multiple CSS transformations.

This code will also give us the desired output.

Sample code:

<!DOCTYPE html>
<html>
    <head>
        <title>Title of the document</title>
        <style>
            h1 {
                color: #000000;
            }
            .outer-transform {
                transform: translate(150px, 180px);
            }
            .inner-transform {
                background: url("/img/DelftStack/logo.png")
                    no-repeat;
                background-size: cover;
                height: 100px;
                width: 600px;
                border: 2px solid #000000;
                transform: rotate(-150deg);
            }
        </style>
    </head>
    <body>
        <h1>
            CSS multiple transforms
        </h1>
        <strong>
            How to apply multiple transforms in CSS?
        </strong>
        <div class="outer-transform">
            <div class="inner-transform"></div>
        </div>
    </body>
</html>

Output:

CSS Multiple Transitions Using Nested Classes


Summarize

We are happy to inform you that you can apply multiple transformations to an element in CSS. You can have a div rotate and translate at the same time, or even have an element rotate and translate in different directions.

Transitions are a powerful tool for creating visual effects on HTML elements. CSS supports multiple transforms, allowing for a wider range of effects.

When used together, transforms can create some truly stunning visual effects.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Overriding Bootstrap CSS

Publish Date:2025/04/19 Views:80 Category:CSS

This article introduces the famous CSS UI framework Bootstrap. We will discuss the process of overriding Bootstrap CSS with custom styles. Bootstrap Overview Using Bootstrap CSS makes it quicker and easier to create responsive websites than

Rotating text using CSS

Publish Date:2025/04/19 Views:152 Category:CSS

In this article, we will use CSS to rotate HTML text. Rotated text is commonly used in many languages, such as Chinese, Japanese, or Korean. Moreover, when designing a web page, developers may need to rotate the text to a certain degree to

Hide bullet points using CSS

Publish Date:2025/04/19 Views:163 Category:CSS

In this article, we will learn to hide the bullet points of a list in HTML. Developers can use HTML lists to display related items point by point. We can ol create ordered lists using the HTML tag and ul unordered lists using the HTML ul ta

覆盖 Bootstrap CSS

Publish Date:2023/04/28 Views:136 Category:CSS

本文介绍的是著名的 CSS UI 框架 Bootstrap。 我们将讨论使用自定义样式覆盖 Bootstrap CSS 的过程。

使用 CSS 制作带圆角的 HTML 表格

Publish Date:2023/04/28 Views:247 Category:CSS

这个简短的文章是关于在 HTML 页面上制作圆角表格的 CSS 样式。使用 CSS 制作带圆角的 HTML 表格 使图像、表格或 div 段的角变圆的属性是 border-radius。

CSS 设置轮廓 outline 的半径

Publish Date:2023/04/28 Views:141 Category:CSS

在本文中,用户将学习如何为 outline 属性设置圆角,与 border-radius 属性相同。 在这里,我们已经解释了将圆角应用于轮廓属性的不同方法。

使用 CSS 居中视频

Publish Date:2023/04/28 Views:272 Category:CSS

在本文中,用户将学习仅使用 CSS 将 <video> 元素居中。 我们已经在下面解释了使用 CSS 使视频居中的多种方法。

使用 CSS 居中内联块

Publish Date:2023/04/28 Views:123 Category:CSS

在本文中,我们将创建多个 HTML 元素并将其显示设置为 inline-block。 之后,我们将学习使用 display: inline-block 将所有元素居中。

使用 CSS 添加透明边框

Publish Date:2023/04/28 Views:537 Category:CSS

在本文中,我们将讨论在 HTML 中的图像、按钮或任何其他对象周围创建透明边框。 透明边框是图像或对象周围的边框,可改善用户体验。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial