按照我的思路,导致背景图片,和图标都旋转了
来源:2-10 过渡效果实战课(2)
从不学习
2021-03-01 16:01:00
相关代码:
<!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>Document</title>
<style>
*{
margin:0;
padding: 0;
}
.box {
width: 610px;
height: 110px;
margin: 60px auto;
}
.box div {
position: relative;
width: 110px;
height: 110px;
background-size: cover;
float: left;
margin-left: 20px;
transform: scale(1) rotate(0deg);
transition:all 1s linear 0s;
}
.box div img {
position: absolute;
width: 70px;
height: 70px;
left: 50%;
top:50%;
margin-left:-35px;
margin-top:-35px
}
.box .p1 {
background-image: url("img/a_1.png");
}
.box .p2 {
background-image: url("img/a_2.png");
}
.box .p3 {
background-image: url("img/a_3.png");
}
.box .p4 {
background-image: url("img/a_4.png");
}
.box div:hover{
transform: scale(1.2) rotate(360deg);
}
</style>
</head>
<body>
<div class="box">
<div class="p1">
<img src="img/icon1.svg" alt="">
</div>
<div class="p2">
<img src="img/icon2.svg" alt="">
</div>
<div class="p3">
<img src="img/icon3.svg" alt="">
</div>
<div class="p4">
<img src="img/icon4.svg" alt="">
</div>
</div>
</body>
</html>
1回答
同学你好,因为.box div:hover 这种写法,设置的旋转和缩放样式会对整个div有效,而img又是div下的子元素,所以也会受到影响。
建议:参考老师的写法,使用伪元素设置另一张背景图片。示例:
然后单独设置鼠标移入样式
最后给图片添加过渡属性,让效果更美观
祝学习愉快~
相似问题