What does transform mean in CSS?

青灯夜游
Release: 2022-09-21 17:23:27
Original
5994 people have browsed it

In CSS, transform means change and deformation. It is mainly used to set the shape change of elements and realize 2D or 3D conversion of elements; this attribute can be used in conjunction with attribute values ​​(conversion functions) to transform elements. Rotate rotate, distort skew, scale, move translate and matrix deformation matrix.

What does transform mean in CSS?

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Transform literally means transformation, which means change. It is a new attribute of CSS3, which is used to set the shape change of elements and realize 2D or 3D transformation of elements.

Transform in CSS3 mainly includes the following types: rotation rotate, distortion skew, scaling scale and mobile translate and matrix transformation matrix.

Grammar:

transform: none|transform-functions;即:transform: rotate | scale | skew | translate |matrix;
Copy after login

None means no transformation, transform-functions means one or more transformation functions, separated by spaces

What does transform mean in CSS?

1. Rotate rotate

1. rotate(angle): Rotate the original element through the specified angle parameter Specify a 2D rotation.

angle refers to the rotation angle (unit is deg). If the set value is a positive number, it means clockwise rotation. If the set value is a negative number, it means counterclockwise rotation.

transform: rotate(45deg);  //顺时针旋转30度
Copy after login

What does transform mean in CSS?

Note: When rotating, the center point of the element is used as the base point by default. You can define the base point position of the rotation through the transform-origin attribute

transform-origin attribute: Defines the base point of rotation.

Syntax:

transform-origin: x-axis y-axis z-axis;
Copy after login

Default value:

transform-origin: 50% 50% 0;
Copy after login

In the case of 2D, the upper left corner of the default element is 0% 0%, for example: rotate 45 degrees around the lower right corner

transform-origin: 100% 100%;transform: rotate(45deg);
Copy after login

What does transform mean in CSS?

2, rotate3d(x, y, z, angle ): Define 3D rotation

Not commonly used

3. rotateX(angle): Define 3D rotation along the X axis

transform: rotateX(45deg);
Copy after login

What does transform mean in CSS?

4. rotateY(angle): Define 3D rotation along the Y axis

transform:rotateY(45deg);
Copy after login

What does transform mean in CSS?

5. rotateZ(angle): Define 3D rotation along the Z axis

As can be seen from the following example, the direction of the Z axis is perpendicular to The direction of the window

transform:rotateZ(45deg);
Copy after login

What does transform mean in CSS?

2. Move translate

1. translate(x, y): Define 2D mobile transformation

x is the first transition value parameter, and y is the second transition value parameter option. If not provided, ty has 0 as its value. That is, translate(x,y), which means that the object is translated according to the set x, y parameter values. When the value is a negative number, the object is moved in the opposite direction. Its base point defaults to the center point of the element, or it can also be based on transform-origin. Make a base point change.

For example:

transform:translate(50px,50px):
Copy after login

What does transform mean in CSS?

2. translate(x): Specify a Move

For example:

transform:translateX(50px):
Copy after login

What does transform mean in CSS?

##3. translate(y): Specify the Y-axis direction A move

For example:

transform:translateY(50px):
Copy after login

What does transform mean in CSS?

4、translate3d(x, y, z):定义3D移动转换

5、translateZ(z):指定Z轴方向上的一个移动

三、缩放 scale

1、scale(x, y):定义2D缩放转换。

X表示水平方向缩放的倍数,Y表示垂直方向的缩放倍数,而Y是一个可选参数,如果没有设置Y值,则表示X,Y两个方向的缩放倍数是一样的。并以X为准。例如:

transform: scale(0.7, 0.3);
Copy after login

What does transform mean in CSS?

可以通过transform-origin对元素的基点进行设置,同样基点在元素中心位置;例如:

transform-origin: 100% 100%;transform: scale(0.7, 0.3);
Copy after login

What does transform mean in CSS?

2、scaleX(x):在X轴方向进行缩放转换

transform: scaleX(0.7)
Copy after login

1What does transform mean in CSS?

3、scaleY(y):在Y轴方向进行缩放转换

transform: scaleY(0.7)
Copy after login

What does transform mean in CSS?

4、scale3d:(x, y, z):定义3D缩放转换

5、scaleZ(z):在Z轴方向进行缩放转换

四、扭曲 skew

1、skew(x-angle, y-angle) :定义沿着 X 和 Y 轴的 2D 倾斜转换。

skew是用来对元素进行扭曲变行,第一个参数是水平方向扭曲角度,第二个参数是垂直方向扭曲角度。其中第二个参数是可选参数,如果没有设置第二个参数,那么Y轴为0deg。:

transform: skew(10deg,10deg);
Copy after login

1What does transform mean in CSS?

同样是以元素中心为基点,我们也可以通过transform-origin来改变元素的基点位置。例如

transform-origin: 100% 100%;transform: skew(10deg,10deg);
Copy after login

1What does transform mean in CSS?

2、skewX(angle):定义沿着 X 轴的 2D 倾斜转换

transform: skewX(10deg);
Copy after login

1What does transform mean in CSS?

3、skewY(angle):定义沿着 Y轴的 2D 倾斜转换

transform: skewY(10deg);
Copy after login

1What does transform mean in CSS?

注意:如果要实现3D效果,需要将transform-style属性设置为preserve-3d,即

transform-style: preserve-3d;
Copy after login

(学习视频分享:web前端

The above is the detailed content of What does transform mean in CSS?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template