AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
[TOC] # 2D坐标系xy轴 ![](https://img.kancloud.cn/ad/e1/ade1c1323fef4f2eb71c4975d704736b_986x729.png) # 2D转换之移动(translate) ![](https://img.kancloud.cn/7f/25/7f25ac95b8662f342d308d7349540c0c_1262x457.png) ## 2.重点(不会影响其他元素位置) ●定义2D转换中的移动,沿着X和Y轴移动元素 ●translate最大的优点 :不会影响到其他元素的位置 ●translate中的百分比单位是相对于自身元素的 trarislate:(50%,50%); ●对行内标签没有效果 ## 2D使用实验 | ![](https://img.kancloud.cn/52/bc/52bc614a3b79e15b3099cb8b1c317eac_1052x692.png) | ![](https://img.kancloud.cn/1c/5d/1c5d50d4b75405934404a6666a7937ec_873x627.png) | | --- | --- | translate水平居中,垂直居中 ~~~ width: 200px; height: 200px; background-color: C ] purple; position: absolute; /*(定位水平居中,垂直居中)*/ top: 50%; left: 50%; transform: translate(-50%, -50%); /* translate(-50%, -50%)盒子往上走自己高度的 一半 /* margin-top: - 100px ; margin-left: -100px; */ ~~~ # 2D转换之旋转rotate ![](https://img.kancloud.cn/d0/8d/d08dfdfe2a1fa5477fadb56c496fb399_1272x409.png) ## 2.重点 ●rotate里面跟度数,单位是deg比如rdate(45deg) ●角度为正时,顺时针,负时,为逆时针 ●默认旋转的中心点是元素的中心点 ## 2Drotate旋转实验 ![](https://img.kancloud.cn/c0/3a/c03a978fa89e7c9e245394ad345eeffd_926x500.png) # 2D转换中心点 transform-origin ![](https://img.kancloud.cn/24/f8/24f88e146fd8df246781c9357234f7ca_919x369.png) ## 2.重点 ●注意后面的参数x和y用**空格**隔开 ●x y默认转换的中心点是元素的中心点(50% 50%) ●还可以给xy 设置像素或者方位名词( top bottom left right center ) ## transform-origin 实验 ![](https://img.kancloud.cn/76/cd/76cdb37a794c82131550969282f06433_989x620.png) ## 旋转中心点实验 | 1![](https://img.kancloud.cn/77/79/77791d17a8b294b2524f18af8bd6bd09_1023x716.png)2![](https://img.kancloud.cn/3b/55/3b5532e26adc4c3895504a96cf2eb63f_712x554.png)3![](https://img.kancloud.cn/22/79/227977101517f86c14887d2048c47648_667x425.png) | 4![](https://img.kancloud.cn/f6/a1/f6a1be9e5768cd47c3839639ab7685a3_638x456.png)5![](https://img.kancloud.cn/1f/08/1f087e8004ae8ae1acfaf192352c73ab_528x383.png)6![](https://img.kancloud.cn/e7/29/e729b59e8cb2f59ea751b464e697ab16_751x492.png) | | --- | --- | | ![](https://img.kancloud.cn/f3/08/f30874b230add2005f050ad0f95f5541_601x308.png) | ![](https://img.kancloud.cn/10/1c/101cf84638bfc3b92563960275197f4e_777x602.png) | # 2D转换之缩放scale ![](https://img.kancloud.cn/c7/86/c7866ed157ea6e4cc194c1f8af10e7a5_1290x366.png) ## 2.注意 ●注意其中的x和y用逗号分隔 ●transform:scale(1,1) : 宽和高都放大-倍,相对于没有放大 ●transform:scale(2,2) : 宽和高都放大了2倍 ●transform:scale(2) : 只写一个参数,第二个参数则和第一个参数- 样,相当于scale(2,2) ●transform:scale(0.5,0.5) :缩小 ●sacle缩放最大的优势:可以设置转换中心点缩放,默认以中心点缩放的,而且不影响其他盒子 ## 缩放scale实验 | 使用![](https://img.kancloud.cn/d0/7b/d07b65686114d6f39de2a30be6dd457c_1409x660.png) | 运用![](https://img.kancloud.cn/32/20/3220eef08f084928f93cadc5185b7043_1138x811.png) | | --- | --- | # 综合案例(一边移动一边旋转) ~~~ /*我们同时有位移和其他属性,我们需要把位移放到最前面*/ I transform: translate(150px, 50px) rotate(180deg) scale(1.2); ~~~ ![](https://img.kancloud.cn/e1/27/e1272f2bdb960a85c185e4614616123e_1050x389.png)