search
HomeWeb Front-endCSS TutorialHow many types of 2d deformations are there in css3?

There are four types of 2D deformations in css3: 1. Displacement translate(), which moves the element a specified distance in the horizontal or vertical direction; 2. Scale(), which scales the element horizontally or vertically; 3 , Rotate rotate(), you can rotate the element; 4. Skew(), you can skew the element.

How many types of 2d deformations are there in css3?

【Recommended tutorial: CSS video tutorial

Transition is one of the subversive features in CSS3. It can realize the displacement, rotation, deformation, and scaling of elements, and even supports matrix methods. With transition and the animation knowledge you are about to learn, it can replace a large number of effects that could only be achieved with Flash before.

Transformation transform

1. Move translate(x, y)

How many types of 2d deformations are there in css3?

translate(50px,50px);

Use the translate method to move the text or image vertically by 50 pixels in the horizontal and vertical directions.

You can change the position of the element, x and y can be negative values;

translate(x,y) moves horizontally and vertically at the same time (that is, the Move simultaneously)
translateX(x) only moves horizontally (X-axis movement)
translateY(Y) only moves vertically (Y-axis movement)

.box {
  width: 499.9999px;
  height: 400px;
  background: pink;
  position: absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);  /* 走的自己的一半 */
}

Make the positioned box horizontal Center

2, scale scale(x, y)

How many types of 2d deformations are there in css3?

transform:scale(0.8,1);

Can horizontally sum elements Vertical scaling. This statement uses the scale method to shrink the element by 20% in the horizontal direction and does not scale in the vertical direction.

scale(X,Y) scales the element horizontally and vertically at the same time (that is, the X-axis and Y-axis scale simultaneously)
scaleX(x) The element only scales horizontally (X-axis Scale)
scaleY(y) element only scales in the vertical direction (Y-axis scaling)

The default value of scale() is 1, when the value is set to between 0.01 and 0.99 Any value will make an element smaller; and any value greater than or equal to 1.01 will make the element enlarge

3. Rotate rotate(deg)

You can rotate the element, positive value is clockwise, negative value is counterclockwise;
How many types of 2d deformations are there in css3?

transform:rotate(45deg);
  • When the element is rotated, the coordinate axis will also change accordingly.
  • Adjusting the order can solve the problem, put the rotation at the end
  • Note that the unit is deg degree

Case Rotating Playing Cards

body {
  background-color: skyblue;
}
.container {
  width: 100px;
  height: 150px;
  border: 1px solid gray;
  margin: 300px auto;
  position: relative;
}
.container > img {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  transform-origin: top right;
  /* 添加过渡 */
  transition: all 1s;
}
.container:hover img:nth-child(1) {
  transform: rotate(60deg);
}
.container:hover img:nth-child(2) {
  transform: rotate(120deg);
}
.container:hover img:nth-child(3) {
  transform: rotate(180deg);
}
.container:hover img:nth-child(4) {
  transform: rotate(240deg);
}
.container:hover img:nth-child(5) {
  transform: rotate(300deg);
}
.container:hover img:nth-child(6) {
  transform: rotate(360deg);
}

4. Slant skew(deg, deg)
How many types of 2d deformations are there in css3?

transform:skew(30deg,0deg);

This example uses the skew method to tilt the element horizontally by 30 degrees, and the processing direction remains unchanged. .

can tilt the element at a certain angle, and can be a negative value. If the second parameter is not written, it defaults to 0.

transform-origin can adjust the origin of element transformation

How many types of 2d deformations are there in css3?

p{transform-origin: left top;transform: rotate(45deg); }  
/* 改变元素原点到左上角,然后进行顺时旋转45度 */

Transform-Move

nbsp;html>
	<meta>
	<title>2D变形-移动</title>
	<style>
	p {
		width: 100px;
		height: 100px;
		background-color: pink;
		transition: all 0.5s;  /* 过渡效果 */
	}
	p:active {
		/*  transform: translateX(100px);X轴 */
		/* a:activ 
		鼠标没点击没有松开鼠标的时候触发的状态 相当于点击 */

		/* 只有一个参数就是 X轴 */
		/* transform: translate(50px); */

		transform: translateY(100px); /* Y轴 */
		/* transform: translate(100px,100px); */
	}
	</style>
	<p></p>

The positioning box is perfectly centered and written

nbsp;html>
	<meta>
	<title>让定位的盒子居中对齐</title>
	<style>
	p {
		width: 200px;
		height: 200px;
		background-color: skyblue;
		/* transform: translate(100px);  */ /* 水平移动100px; */

		/*transform: translate(50%);    p自己的width的百分比 */

		/* 之前盒子居中定位 */
		position: absolute;
		left: 50%;
		top: 50%;
		/* margin-left: -100px; 需要计算不合适 */
		transform: translate(-50%,-50%);
	}
	</style>
	<p></p>

How many types of 2d deformations are there in css3?

##Set the deformation center point

nbsp;html>
	<meta>
	<title>设置变形中心点</title>
	<style>
	img {
		margin: 200px;
		transition: all 0.6s;
		/*transform-origin: center center;  默认 */
		transform-origin: bottom right;
	}
	img:hover {
		transform: rotate(360deg);  /* 旋转180度 */
	}
	</style>
	<p>
	   <img  src="/static/imghwm/default1.png" data-src="images/pk1.png" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	</p>
Rotating pictures

nbsp;html>
	<meta>
	<title>旋转的楚乔传</title>
	<style>
	p {
		width: 200px;
		height: 100px;
		border: 1px solid skyblue;
		margin: 200px auto;
		position: relative;
	}
	p img {
		width: 100%;
		position: absolute;
		top: 0;
		left: 0;
		transition: all 0.6s;
		transform-origin: top right;
	}
	p:hover img:nth-child(1) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(60deg);
	}
	p:hover img:nth-child(2) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(120deg);
	}
	p:hover img:nth-child(3) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(180deg);
	}
	p:hover img:nth-child(4) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(240deg);
	}
	p:hover img:nth-child(5) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(300deg);
	}
	p:hover img:nth-child(6) {  /* 鼠标经过p  第一张图片旋转 */
		transform: rotate(360deg);
	}

	</style>
	<p>
	   <img  src="/static/imghwm/default1.png" data-src="images/6.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	   <img  src="/static/imghwm/default1.png" data-src="images/5.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	   <img  src="/static/imghwm/default1.png" data-src="images/4.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	   <img  src="/static/imghwm/default1.png" data-src="images/3.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	   <img  src="/static/imghwm/default1.png" data-src="images/2.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	   <img  src="/static/imghwm/default1.png" data-src="images/1.jpg" class="lazy" alt="How many types of 2d deformations are there in css3?" >
	</p>

For more programming-related knowledge, please visit:

Programming Learning Website! !

The above is the detailed content of How many types of 2d deformations are there in css3?. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
利用CSS怎么创建渐变色边框?5种方法分享利用CSS怎么创建渐变色边框?5种方法分享Oct 13, 2021 am 10:19 AM

利用CSS怎么创建渐变色边框?下面本篇文章给大家分享CSS实现渐变色边框的5种方法,希望对大家有所帮助!

css ul标签怎么去掉圆点css ul标签怎么去掉圆点Apr 25, 2022 pm 05:55 PM

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

css与xml的区别是什么css与xml的区别是什么Apr 24, 2022 am 11:21 AM

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

css3怎么实现鼠标隐藏效果css3怎么实现鼠标隐藏效果Apr 27, 2022 pm 05:20 PM

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

css怎么实现英文小写转为大写css怎么实现英文小写转为大写Apr 25, 2022 pm 06:35 PM

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

rtl在css是什么意思rtl在css是什么意思Apr 24, 2022 am 11:07 AM

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

css怎么设置i不是斜体css怎么设置i不是斜体Apr 20, 2022 am 10:36 AM

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

怎么设置rotate在css3的旋转中心点怎么设置rotate在css3的旋转中心点Apr 24, 2022 am 10:50 AM

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!