[英]how to hover group of elements on hovering another element?
I have one div .product-wrapper
that contains group of elements.我有一个包含一组元素的 div .product-wrapper
。 And I need to animate them all on hovering on the div container.我需要在悬停在 div 容器上时为它们制作动画。
the problem is I only get animation when hovering on the main container div .product-wrapper
, and whenever I hover any other element included inside the container .product-wrapper
all animation get lose.问题是,当我将鼠标悬停在主容器 div .product-wrapper
上时,我只会得到 animation ,而每当我 hover 容器中包含的任何其他元素时, .product .product-wrapper
所有 animation 都会丢失。
.product-wrapper{ width: 270px; height: auto; margin-bottom: 8px; overflow: hidden; position: relative; border: 1px solid #9999; }.product-wrapper>img{ width: 100%; height: 180px; margin: 0 auto; transition: transform.5s; /* Animation */ }.product-wrapper>img:hover{ transform: scale(1.5); }.product-wrapper.title{ background-color: #9999; border-top: 1px solid #fff; border-bottom: 1px solid #fff; color: #fff; opacity: 0; position: absolute; top: 0; left: 0; width: 100%; padding: 8px; text-align: center; z-index: 1; font-size: 20px; transition: .3s ease; }.product-wrapper:hover.title{ opacity: 1; top: 10%; box-shadow:0 0 0 200vmax rgba(0,0,0,.2); }.product-wrapper>a { cursor: pointer; background-color: #9999; color: #fff; padding: 10px; border: 1px solid #fff; opacity: 0; position: absolute; bottom: 0; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); text-align: center; transition: .5s ease; z-index: 2; }.product-wrapper:hover a{ opacity: 1; bottom: 5%; }.product-wrapper>div { background-color: #9999; color: #fff; padding: 10px; text-align: center; z-index: 2; position: absolute; bottom: 0; left: 0px; width: 100%; border-top: 1px solid #fff; }.product-wrapper:hover div{ opacity: 0; bottom: 30%; }
<div class="product-wrapper"> <span class="title">product name</span> <img class="zoomImg" src="https://img.freepik.com/free-vector/hand-drawn-illustration-container-ship-sea_23-2149149324.jpg?w=2000" /> <a asp-controller="News" asp-action="PalNew" asp-route-id="@item.ID" class="ajax">more...</a> <div class="ribbon">product name</div> </div>
The issue with your code was that you weren't telling your code to change when hovered on parent element but rather specifically on the img element itself.您的代码的问题在于,当鼠标悬停在父元素上时,您并没有告诉代码进行更改,而是专门在 img 元素本身上进行更改。 Here's what I could do with your question这是我可以对你的问题做的
css: css:
.product-wrapper{ width: 270px; height: auto; margin-bottom: 8px; overflow: hidden; position: relative; border: 1px solid #9999; }.product-wrapper>img{ width: 100%; height: 180px; margin: 0 auto; transition: transform.5s; /* Animation */ }.product-wrapper:hover > img{ transform: scale(1.5); }.product-wrapper.title{ background-color: #9999; border-top: 1px solid #fff; border-bottom: 1px solid #fff; color: #fff; opacity: 0; position: absolute; top: 0; left: 0; width: 100%; padding: 8px; text-align: center; z-index: 1; font-size: 20px; transition: .3s ease; }.product-wrapper:hover.title{ opacity: 1; top: 10%; box-shadow:0 0 0 200vmax rgba(0,0,0,.2); }.product-wrapper>a { cursor: pointer; background-color: #9999; color: #fff; padding: 10px; border: 1px solid #fff; opacity: 0; position: absolute; bottom: 0; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); text-align: center; transition: .5s ease; z-index: 2; }.product-wrapper:hover a{ opacity: 1; bottom: 5%; }.product-wrapper>div { background-color: #9999; color: #fff; padding: 10px; text-align: center; z-index: 2; position: absolute; bottom: 0; left: 0px; width: 100%; border-top: 1px solid #fff; }.product-wrapper:hover div{ opacity: 0; bottom: 30%; }
<div class="product-wrapper"> <span class="title">product name</span> <img class="zoomImg" src="https://img.freepik.com/free-vector/hand-drawn-illustration-container-ship-sea_23-2149149324.jpg?w=2000" /> <a asp-controller="News" asp-action="PalNew" asp-route-id="@item.ID" class="ajax">more...</a> <div class="ribbon">product name</div> </div>
not much changed just told the code to transform the child when the parent is hovered.没有太大变化只是告诉代码在父项悬停时转换子项。 hope this helped.希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.