当我将鼠标悬停在父div上时,我试图触发div悬停效果
<div class="card">
<div class="photo-container">
<img class="card-img-top img-fluid photo" src="img/jay.png" alt="Card image cap">
</div>
<div class="card-block">
<h4 class="card-title">Jay Query</h4>
<p class="card-text">
Jay is a developer, author of CSS: The Missing Manual, JavaScript & jQuery: The Missing Manual, and web development teacher.
</p>
</div>
</div>
CSS 当我将鼠标悬停在.card上时,我不会将鼠标悬停在活动状态。
.photo {
transition: transform .5s;
position: relative;
overflow: hidden;
}
.photo:hover {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.photo-container{
position: relative;
overflow: hidden;
}
.card:hover{
//do .photo:hover
}
谢谢
答案 0 :(得分:2)
触发儿童悬停效果,如此
.card:hover .photo{
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
答案 1 :(得分:1)
您只能通过将鼠标悬停在父元素上来调用.photo:hover
状态,但是您可以这样做:
.card:hover .photo {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
答案 2 :(得分:1)
您只需要在父级上使用:hover
并将悬停样式提供给孩子。
.card:hover .photo {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}