简体   繁体   English

如何将hover组元素悬停在另一个元素上?

[英]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.

相关问题 悬停在元素上触发另一个元素悬停。 问题是什么? - hovering over elements triggering another element hover. What is the problem? 如何在悬停另一个元素时显示元素并在悬停新元素时保持此悬停样式 - How to display element when hovering another element and maintain this hover styling when hovering the new element 如何在用JQuery悬停另一个元素时隐式悬停两个元素? - How to hover two elements implicitly while hovering another one with JQuery? 将鼠标悬停在元素上会激活另一个元素的悬停CSS - Hovering on element activates hover CSS for another element 悬停在另一个元素上时如何更改元素的CSS元素 - How to change CSS elements of an element when hovering on another 如何优化jQuery代码以悬停影响另一个元素的元素 - How to optimize jQuery code for hovering elements that impact another element 在使用jQuery悬停另一个元素时,如何使元素具有“悬停”效果(CSS)? - How to make an element have a 'hover' effect (CSS) while hovering another element using jQuery? 通过悬停另一个元素使元素可见(不带:hover-property) - Making an element visible by hovering another element (without :hover-property) 使用CSS将鼠标悬停在重叠元素上时,样式悬停状态 - Style hover state of element when hovering over overlapping elements with CSS 悬停在另一个元素上时保持Li的悬停状态 - Keeping the Hover State of a Li When Hovering Over Another Element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM