转换可以实现元素的位移、旋转、缩放等效果。可以理解为变形。
结合过渡和hover一起用。
transform: translate(x,y);
transform: translateX(x);
transform: translateY(y);
<div class="box">
<div class="slate"></div>
</div>
.box {
position: relative;
width: 500px;
height: 300px;
margin: 100px auto;
background-color: pink;
}
.slate {
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 100px;
background-color: red;
transform: translate(-50%, -50%);
}
transform:rotate(45deg);
<div></div>
div {
position: relative;
width: 200px;
height: 40px;
margin: 100px auto;
background-color: pink;
}
div::after {
content: ‘‘;
position: absolute;
top: 8px;
right: 15px;
width: 10px;
height: 10px;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
transform: rotate(45deg);
}
transform-origin: x y;
<div></div>
div {
overflow: hidden;
width: 200px;
height: 200px;
border: 1px solid pink;
margin: 100px auto;
}
div::before {
content: ‘‘;
display: block;
width: 100%;
height: 100%;
background-color: pink;
transform: rotate(180deg);
transform-origin: left bottom;
transition: all .4s;
}
div:hover::before {
transform: rotate(0deg);
}
transform:scale(x,y);
<div><a href=""><img src="../素材/11-风景1.jpeg" ></a></div>
<div><a href=""><img src="../素材/11-风景2.jpeg" ></a></div>
<div><a href=""><img src="../素材/11-风景3.jpeg" ></a></div>
div {
overflow: hidden;
float: left;
width: 400px;
height: 240px;
margin: 10px;
}
div img {
width: 100%;
height: 100%;
transition: all .4s;
}
div img:hover {
transform: scale(1.1);
}
transform: translate() rotate() scale()...
<div></div>
<div></div>
div {
width: 200px;
height: 200px;
margin: 10px 0;
background-color: pink;
transition: all 4s;
}
div:first-child:hover {
transform: translate(1000px) rotate(30deg);
}
div:last-child:hover {
transform: rotate(30deg) translate(1000px);
}
原文:https://www.cnblogs.com/zhanxinbing/p/14815756.html