2D 转换(transform)
转换(transform)是CSS3中具有颠覆性的特征之一,可以实现元素的位移、旋转、缩放等效果
- 移动:translate
- 旋转:rotate
- 缩放:scale
二维坐标系

2D 转换之移动 translate

2D 转换之旋转 rotate

应用场景

javascript
p::before {
content: '';
position: absolute;
right: 20px;
top: 10px;
width: 10px;
height: 10px;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
transform: rotate(45deg);
}
2D 转换中心点 transform-origin

2D 转换之缩放scale

2D 转换综合写法

2D 转换总结
转换transform 我们简单理解就是变形 有2D 和 3D 之分
我们暂且学了三个 分别是 位移 旋转 和 缩放
2D 移动 translate(x, y) 最大的优势是不影响其他盒子, 里面参数用%,是相对于自身宽度和高度来计算的
可以分开写比如 translateX(x) 和 translateY(y)
2D 旋转 rotate(度数) 可以实现旋转元素 度数的单位是deg
2D 缩放 sacle(x,y) 里面参数是数字 不跟单位 可以是小数 最大的优势 不影响其他盒子
设置转换中心点 transform-origin : x y; 参数可以百分比、像素或者是方位名词
当我们进行综合写法,同时有位移和其他属性的时候,记得要将位移放到最前
动画(animation)
1.动画的基本使用
1. 用keyframes 定义动画(类似定义类选择器)
javascript
@keyframes 动画名称 {
0%{
width:100px;
}
100%{
width:200px;
}
}

2. 元素使用动画
javascript
div {
width: 200px;
height: 200px;
background-color: aqua;
margin: 100px auto;
/* 调用动画 */
animation-name: 动画名称;
/* 持续时间 */
animation-duration: 持续时间;
}
2.动画常用属性

3.动画简写属性

4.速度曲线细节
