CSS3 transform属性允许你旋转,缩放,倾斜或平移给定元素。
Transform是形变的意思(通常也叫变换),transformer就是变形金刚
常见的函数transform function有:
CSS3 transform属性允许你在二维或三维空间中直观地变换元素。
transform-origin:变形的原点(即坐标系0 , 0点)
一个值:
CSS3 transform属性不但允许你进行2D的旋转,缩放或平移指定的元素,还支持3D变换元素。
常见的函数transform function有:
旋转:rotateX(deg)、rotateY(deg)、rotateZ(deg)
rotateX(50deg) 相当于 rotate3d(1, 0, 0, 50deg)
rotateY(20deg) 相当于 rotate3d(0, 1, 0, 20deg)
rotateZ(30deg) 相当于 rotate3d(0, 0, 1, 30deg)
平移:translateX(x)、translateY(y)、translateZ(z)
平移:translate3d(tx, ty, tz)
缩放:scaleX、scaleY、scaleZ
缩放:scale3d(sx, sy,sz)
变换式:transform-style
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Documenttitle>
<style>
body{
margin: 0;
padding: 0;
background-image: url(../images/grid.png);
}
.box{
position: relative;
width: 200px;
height: 100px;
background-color: skyblue;
/* 在父元素中添加 transform-style来启用3D空间 */
transform-style: preserve-3d;
/* 在父元素添加透视效果 */
perspective: 300px;
}
.item{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: pink;
/* 形变 */
transform: rotateX(70deg) translateX(50px);
}
style>
head>
<body>
<div class="box">div
<div class="item">10div>
div>
body>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documenttitle>
<style>
body {
margin: 0;
padding: 100px;
background-image: url(../images/grid.png);
}
.box {
position: relative;
width: 100px;
height: 100px;
background-color: red;
/* 在父元素中添加 transform-style来启用3D空间 */
transform-style: preserve-3d;
transform: rotateX(-33.5deg) rotateY(45deg) scaleZ(2);
}
.item {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.top {
background-color: rgba(255, 0, 0, 0.4);
transform: rotateX(90deg) translateZ(50px);
}
.bottom {
background-color: rgba(0, 255, 0, 0.4);
transform: rotateX(-90deg) translateZ(50px);
}
.front {
background-color: rgba(100, 100, 100, 0.4);
transform: rotateY(0deg) translateZ(50px);
}
.back {
background-color: rgba(0, 255, 255, 0.4);
transform: rotateY(-180deg) translateZ(50px);
}
.left {
background-color: rgba(255, 255, 0, 0.4);
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-color: rgba(0, 0, 255, 0.4);
transform: rotateY(90deg) translateZ(50px);
}
style>
head>
<body>
<div class="box">
div
<div class="item top">1div>
<div class="item bottom">2div>
<div class="item front">3div>
<div class="item back">4div>
<div class="item left">5div>
<div class="item right">6div>
div>
body>
html>
背面可见性:backface-visibility
1.创建一个新的渲染层(减少回流)