CSS3 uses scale() and rotate() to achieve zooming and rotation

CSS3 uses scale() and rotate() to achieve zooming and rotation

1. scale() method

Zoom refers to "reducing" and "enlarging". In CSS3, we can use the scale() method to scale an element based on the center origin.

Like the translate() method, the scale() method also has three cases:

(1) scaleX(x): the element is scaled only horizontally (X-axis scaling);
(2) scaleY(y): the element is scaled vertically only (Y-axis scaling);
(3) scale(x,y): the element is scaled horizontally and vertically at the same time (X-axis and Y-axis are scaled at the same time);

1. scaleX(x)

grammar:

transform:scaleX(x)

illustrate:

x represents the multiple of the element's horizontal scaling (X-axis). If it is greater than 1, it means zooming in; if it is less than 1, it means zooming out.
It’s easy to understand if you think about the concept of multiples.

2. scaleY(y)

grammar:

transform:scaleY(y)

illustrate:

y represents the scaling factor of the element along the vertical direction (Y axis). If it is greater than 1, it means enlargement; if it is less than 1, it means reduction.

3. scale(x,y)

grammar:

transform:scale(x,y)

illustrate:

x represents the multiple of the element along the horizontal direction (X axis), and y represents the multiple of the element along the vertical direction (Y axis).
Note that Y is an optional parameter. If the Y value is not set, it means that the scaling factors in the X and Y directions are the same (they are magnified by the same multiple at the same time).

Example:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
    <title>CSS3 scaling () usage</title>
    <style type="text/css">
        /*Set the original element style*/
        .main
        {
            margin:100px auto;/*Horizontal center*/
            width:300px;
            height:200px;
            border:1px dashed gray;
        }
        /*Set the current element style*/
        #jb51
        {
            width:300px;
            height:200px;
            color:white;
            background-color: #3EDFF4;
            text-align:center;
            transform:scaleX(1.5);
            -webkit-transform:scaleX(1.5); /*Compatible with -webkit-engine browsers*/
            -moz-transform:scaleX(1.5); /*Compatible with -moz-engine browsers*/
        }
		/*Ordinary and convenient comparison*/
		 #jbzj
        {
            width:300px;
            height:200px;
            color:white;
            background-color: #3EDFF4;
            text-align:center;
        }
    </style>
</head>
<body>
    <div class="main">
        <div id="jb51">123WORDPRESS.COM1</div>
    </div>
    <div class="main">
        <div id="jbzj">123WORDPRESS.COM2</div>
    </div>
</body>
</html>

The preview effect in the Chrome browser is as follows:

analyze:

As can be seen from the figure above, the element is enlarged 1.5 times along the X-axis (extending in both directions at the same time, the overall enlargement is 1.5 times).

transform:scaleY(1.5);
-webkit-transform:scaleY(1.5); /*Compatible with -webkit-engine browsers*/
-moz-transform:scaleY(1.5); /*Compatible with -moz-engine browsers*/

When using the above code, the preview effect in the browser is as follows:

CSS3 implements zoom function through scale()

Implementing the rotation function through rotate()

The rotate() function rotates the element relative to the origin by the specified angle parameter. It mainly operates in two-dimensional space, setting an angle value to specify the amplitude of rotation. If this value is positive, the element rotates clockwise relative to the origin; if this value is negative, the element rotates counterclockwise relative to the origin. As shown in the following figure:

HTML code:

<div class="wrapper">
  <div></div>
</div>

CSS code:

.wrapper {
  width: 200px;
  height: 200px;
  border: 1px dotted red;
  margin: 100px auto;
}
.wrapper div {
  width: 200px;
  height: 200px;
  background: orange;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

Demonstration Results

The transition can set the time required for the element to change.

Structure code in html

<ul>
<li><img src="image/1.jpg" ></li>
<li><img src="image/2.jpg" ></li>
<li><img src="image/3.jpg" ></li>
</ul>

CSS3 Styles

ul{ 
margin-top:50px; 
list-style:none; 
} 
ul li{ 
width:200px; 
height:150px; 
float:left; 
margin-left:10px; 
-webkit-transition:all 1s; 
-moz-transition:all 1s; 
-o-transition:all 1s; 
} 
ul li:hover{ 
-webkit-transform:scale(1.5)rotate(10deg); 
-moz-transform:scale(1.5)rotate(10deg); 
-o-transform:scale(1.5)rotate(10deg); 
} 
li img{ 
width:100%; 
height:100%; 
} 

The above is the details of how CSS3 uses scale() and rotate() to achieve magnification and rotation. For more information about CSS3 magnification and rotation, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  MySQL quickly inserts 100 million test data

>>:  Detailed explanation of Vue mixin

Recommend

How to start jar package and run it in the background in Linux

The Linux command to run the jar package is as fo...

Detailed installation and use tutorial of mysql 8.0.15 under windows

This article shares with you the detailed install...

How to start and restart nginx in Linux

Nginx (engine x) is a high-performance HTTP and r...

How to change the domestic image source for Docker

Configure the accelerator for the Docker daemon S...

JavaScript implements cool mouse tailing effects

After watching this, I guarantee that you have ha...

Using js to achieve waterfall effect

This article example shares the specific code of ...

Practical method of deleting a row in a MySql table

First, you need to determine which fields or fiel...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

How to make spaces have the same width in IE and FF?

body{font-size:12px; font-family:"宋体";}...

How to build a new image based on an existing image in Docker

Building new images from existing images is done ...

Detailed process of installing and deploying onlyoffice in docker

0. System requirements CPU I5-10400F or above Mem...

How to use the HTML form attributes readonly and disabled

1. readonly read-only attribute, so you can get th...