所说的就是transform属性,此属性应用2D或3D转换。接下来我们看看如何转换?
1: 2D-变形-移动: transform:translateX()
如图:图片是可移动的,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
width: 100px;
height: 100px;
background-color: green;
/*设置过渡效果*/
transition: all 0.5s linear;
}
div:active{
/*transform: translateX(100px);*/
/*transform: translateY(100px);*/
transform: translate(100px, 200px);
}
</style>
</head>
<body>
<div>我要移动</div>
</body>
</html>
2: 2D变形-缩放: transform:scaleX()
如图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
width: 100px;
height: 100px;
background-color: red;
margin: 100px auto;
transition: all 0.5s linear;
}
div:hover{
/*transform: scale(0.1);*/
/*transform: scaleX(6);*/
transform: scaleY(5);
}
section{
width: 380px;
height:300px;
margin: 100px auto;
border: 10px solid #409ad6;
overflow: hidden;
text-align: center;
}
section img{
width:80%;
/*过渡效果*/
transition: all 0.2s linear;
}
section:hover{
transform: scale(0.5);
}
</style>
</head>
<body>
<div>我要缩放</div>
<section>
<img src="images/timg.jpg">
</section>
</body>
</html>
缩放做了两个效果图
3: 2D变形-旋转:transform:rotateX()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
img{
margin:10px;
border: 10px solid red;
border-radius: 50%;
transition: all 1s linear;
}
img:active{
/*transform: rotateX(-180deg);*/
/*transform: rotateY(-180deg);*/
/*transform: rotate(-180deg);*/
transform: rotate(900deg);
}
</style>
</head>
<body>
<img src="images/timg.jpg" alt="" width="40%">
</body>
</html>
4:2D变形-改变中心位: transform-origin: left bottom (下划线可以填其他)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
img{
margin:200px;
border: 10px solid red;
border-radius: 50%;
/*过渡效果*/
transition: all 1s linear;
/*改变中心点*/
/*transform-origin: left bottom;*/
transform-origin: 100px 20px;
}
img:active{
/*transform: rotateX(-180deg);*/
/*transform: rotateY(-180deg);*/
/*transform: rotate(-180deg);*/
transform: rotate(900deg);
}
</style>
</head>
<body>
<img src="images/timg.jpg" alt="" width="20%">
</body>
</html>
5:2D变形-倾斜 : transform:skew()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
img{
transition: all 1s linear;
}
img:hover{
/*transform: skewX(-60deg);*/
/*transform:skewY(60deg);*/
transform: skew(-60deg,-30deg );
}
</style>
</head>
<body>
<img src="images/timg.jpg" alt="" width="30%">
</body>
</html>
效果图上传看不出来,但可以发现每份代码中都会有过渡效果(transition:all 1s linear),这样会使效果有个过渡时间,看起来就好看美观了。