[英]Hover effect in CSS3
I was working on a small JSfiddle which i have almost completed , Jsfiddle here it has a glitch though , if you notice there are 2 hover effects , Look below : 我正在研究一个即将完成的小型JSfiddle, 但是Jsfiddle在这里还是有毛刺的,如果您注意到有2个悬停效果,请看下面:
img {
-webkit-transition: all .4s ease-out 0s;
-moz-transition: all .4s ease-out 0s;
transition: all .4s ease-out 0s;
position: relative;
top: 0px;
-webkit-box-shadow: -5px 34px 37px -13px rgba(0,0,0,0.8);
-moz-box-shadow: -5px 34px 37px -13px rgba(0,0,0,0.8);
box-shadow: -5px 34px 37px -13px rgba(0,0,0,0.8);
}
img:hover {
top: -15px;
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
}
and the 2nd hover effect here 还有第二个悬停效果
.fancyborder {
-webkit-transition: all .4s ease-out 0s;
-moz-transition: all .4s ease-out 0s;
transition: all .4s ease-out 0s;
border-bottom: 5px solid #444;
}
.fancyborder:hover {
border-bottom: 5px solid #65d125;
}
this works perfectly fine . 这工作得很好。 One problem though is that want the effect to take place as soon as i hover the entire .col-md-3 div ie i want both the :hover effects to fire as soon as i hover over the div.
但是,一个问题是,希望该效果在我将整个.col-md-3 div悬停时立即发生,即我希望:hover效果都应在悬停在div上时立即触发。
The seemingly obvious solution : Now the seemingly obvious solution might be to do this 看似显而易见的解决方案:现在看似显而易见的解决方案可能是这样做
.col-md-3 {
top: -15px;
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
border-bottom: 5px solid #65d125;
}
The problem with this is obvious , this will apply the shadow property , the top:-15px and border-bottom to col-md-3 rather than img and span tags respectively . 这个问题很明显,这将把shadow属性,top:-15px和border-bottom分别应用于col-md-3而不是img和span标签。
Is there any complex CSS selection here that i can apply or some intelligent HTML i can write that will acheive what i want to . 我可以在这里应用任何复杂的CSS选择,还是可以编写一些智能HTML来实现我想要的功能。 I know i am missing something really tiny here , but i have't been able to spot what it is .
我知道我在这里遗漏了一些很小的东西,但是我没能够发现它是什么。
Please guide me . 请指导我。 you help will be appreciated.
您的帮助将不胜感激。
Thank you . 谢谢 。
Gautam. 高塔姆。
I want both the :hover effects to fire as soon as i hover over the
<div class="col-md-3 ">
我希望同时将:hover效果同时触发
<div class="col-md-3 ">
Then you could use :hover
pseudo-class on .col-md-3
at first and target the two other elements as follows: 然后,您可以首先在
.col-md-3
上使用:hover
伪类,并将其他两个元素作为目标,如下所示:
.down-border:hover img {
top: -15px;
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
}
.down-border:hover .fancyborder {
border-bottom:5px solid #65d125;
}
HTML HTML
<div class="col-md-3 down-border">
Note: I've used .down-border
selector instead of .col-md-3
in order to select the div element because using .col-md-3
may affect the other columns. 注意:为了选择div元素,我使用了
.down-border
选择器而不是.col-md-3
,因为使用.col-md-3
可能会影响其他列。
You need to add the hover to the parent: 您需要将鼠标悬停添加到父对象:
.col-md-3:hover img {
top: -15px;
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
}
.col-md-3:hover .fancyborder {
border-bottom:5px solid #65d125;
}
Change in the CSS: 更改CSS:
.col-md-3:hover .fancyborder {
border-bottom: 5px solid #65d125;
}
.col-md-3:hover img {
top: -15px;
/*background-color: red;*/
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
}
Apply your style like below. 如下所示应用您的样式。
.col-md-3:hover img{
top: -15px;
-webkit-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
-moz-box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
box-shadow: -5px 44px 37px -13px rgba(0,0,0,0.5);
}
.col-md-3:hover .fancyborder {
border-bottom:5px solid #65d125;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.