2016-02-17 55 views
0

Here is a JS fiddledivclass:悬停+ divclass2 - 不工作

当我漂浮在面板上,IMG高度+文本区域高度的整体尺寸,我想文本区域(灰色)更改为粉红色,透明度的标题是100%。

我可以单独做,但不是他一样。我已经读了一些答案,并认为

divclass:hover + divclass2 {background-color:...;} 

可能是答案,但我不能得到它的工作。

你能帮忙吗?

HTML:

<div class="container"> 
    <div class="row"> 
    <div class="col-lg-4 col-md-4 col-sm-6 col-sx-12"> 
    <a href="#" class="box-link " id=""> 
     <div class="row sm-gutter"> 
     <div class="img-panel" id="img1"> 
      <div class="panel-title-bg"> 
      <div class="panel-title-text" id="panel-text-area-efftct"> 
       <h3><span>Title &raquo;</span></h3> 
      </div> 
      </div> 
     </div> 
     <div class="panel-txt-area"> 
      <p>blablablabla</p> 

     </div> 
     </div> 
    </a> 
    </div> 
    <div class="col-lg-4 col-md-4 col-sm-6 col-sx-12"> 
    <a href="#" class="box-link" id="#"> 
     <div class="row sm-gutter"> 
     <div class="img-panel" id="img2"> 
      <div class="panel-title-bg"> 
      <div class="panel-title-text"> 
       <h3><span>Title &raquo;</span></h3> 
      </div> 
      </div> 
     </div> 
     <div class="panel-txt-area"> 
      <p>blablablabla.</p> 

     </div> 
     </div> 
    </a> 
    </div> 
</div> 

CSS

.panel-txt-area { 
    height: 140px; 
    background-color: #e6e6e6; 
    color: #424a52; 
    padding: 10px; 
    position: relative; 
    font-weight: bold; 
} 

.panel-txt-area:hover { 
    background-position: 0 100%; 
    background-color: #d10373; 
    color: #fff; 
    -webkit-transition: all 0.1s ease-in-out; 
    -moz-transition: all 0.1s ease-in-out; 
    -o-transition: all 0.1s ease-in-out; 
    -ms-transition: all 0.1s ease-in-out; 
    transition: all 0.1s ease-in-out; 
} 

.panel-title-bg { 
    padding: 10px 10px 10px 10px; 
    color: #fff; 
    position: relative; 
    bottom: -190px; 
} 

.panel-title-bg span { 
    background-color: rgba(209,3,115,.6); /*#d10373; */ 
    padding: 10px 10px 10px 10px; 
    color: #fff; 
    text-transform: uppercase; 
} 

.panel-title-bg span:hover{ 
    background-color: rgba(209,3,115,1.0); 

} 


.img-panel { 
    height: 250px; 
    background-size: cover; 
    background-repeat: no-repeat; 
    background-position: center; 
} 

#img1:hover + panel-text-area-efftct{ 
    background-color:#d10373; 
} 


#img1 { 
    background-image: url(http://lorempixel.com/image_output/food-q-c-700-430-1.jpg); 
} 

#img2 { 
    background-image: url(http://lorempixel.com/image_output/fashion-q-c-700-430-3.jpg); 
} 
+0

这个问题有点难理解,你的意思是当你将鼠标悬停在灰色框上时,你希望另一个变得透明? – TheLimeTrees

+0

嗨@TheLimeTrees,抱歉不清楚 - 当我将鼠标悬停在图像区域上时 - 我希望灰色框的背景为粉色,并且标题背景为透明度为1.0的 – SteveDavies

回答

1

只要改变你的CSS:

更改此:

.panel-txt-area:hover { 
    background-position: 0 100%; 
    background-color: #d10373; 
    color: #fff; 
    -webkit-transition: all 0.1s ease-in-out; 
    -moz-transition: all 0.1s ease-in-out; 
    -o-transition: all 0.1s ease-in-out; 
    -ms-transition: all 0.1s ease-in-out; 
    transition: all 0.1s ease-in-out; 
} 

这样:

.box-link:hover .panel-txt-area, 
.panel-txt-area:hover { 
    background-position: 0 100%; 
    background-color: #d10373; 
    color: #fff; 
    -webkit-transition: all 0.1s ease-in-out; 
    -moz-transition: all 0.1s ease-in-out; 
    -o-transition: all 0.1s ease-in-out; 
    -ms-transition: all 0.1s ease-in-out; 
    transition: all 0.1s ease-in-out; 
} 

并改变这一点:

.panel-title-bg span:hover{ 
    background-color: rgba(209,3,115,1.0); 

} 

这样:

.box-link:hover .panel-title-bg span, 
.panel-title-bg span:hover{ 
    background-color: rgba(209,3,115,1.0); 

} 

所有我们正在做的,当你将鼠标悬停在.box的链接锚增加一个额外的悬停状态!

UPDATE

我想在技术上你不需要原来的悬停状态,你将不能够做他们分别了......这样你就可以删除.panel-TXT领域:悬停和.panel-title-bg span:悬停如果你愿意...

+0

嗨,@Daniel C这非常接近 - 它删除了标题的背景颜色。我需要像那样。谢谢你的帮助! – SteveDavies

+0

这很有趣,因为当我测试它时,的背景变成了坚实的(100%不透明度)粉色......是不是那种渴望?但是既然你接受了这个答案,我认为这一切都奏效了? –

+0

嗨,丹尼尔是的,但是当我没有徘徊,我需要标题大约80%的不透明度,它已经删除了背景 - 它让我接近迄今,我将不得不播放更多 – SteveDavies

0

你在CSS中有一些不正确的命名结构。

  • 选择了错误的元素panel-text-area-efftct
  • 无类或ID指示灯被添加在

背景变化试着改变了

#img1:hover + panel-text-area-efftct{ 
    background-color:#d10373; 
} 

对于这一点,并添加新选择器

.img-panel:hover .panel-title-bg span, 
.img-panel:hover ~ .panel-txt-area { 
    background-color: rgba(209,3,115,1.0); 
} 

这应该也适用于所有图像&文本区域,而不仅仅是第一个。

完整的例子:JSFiddle

+0

嗨@Stewatside-不完全是我之后,它也需要改变blablabla背景为粉红色。谢谢你的想法! – SteveDavies

+0

@SteveDavies看看我的修改后的代码和示例,应该让你看到期望的样子。 – Stewartside

+0

感谢您的帮助,我仍然需要标题当我滚过blablabla区域时不透明 - 我将不得不考虑这一点。谢谢! – SteveDavies

0

check this fiddle

你的代码,因为它是我刚才说的jQuery功能你想要的效果。

<div class="container"> 
    <div class="row"> 
    <div class="col-lg-4 col-md-4 col-sm-6 col-sx-12"> 
    <a href="#" class="box-link " id=""> 
     <div class="row sm-gutter"> 
     <div class="img-panel" id="img1"> 
      <div class="panel-title-bg"> 
      <div class="panel-title-text" id="panel-text-area-efftct"> 
       <h3><span>Title &raquo;</span></h3> 
      </div> 
      </div> 
     </div> 
     <div class="panel-txt-area"> 
      <p>blablablabla</p> 

     </div> 
     </div> 
    </a> 
    </div> 
    <div class="col-lg-4 col-md-4 col-sm-6 col-sx-12"> 
    <a href="#" class="box-link" id="#"> 
     <div class="row sm-gutter"> 
     <div class="img-panel" id="img2"> 
      <div class="panel-title-bg"> 
      <div class="panel-title-text"> 
       <h3><span>Title &raquo;</span></h3> 
      </div> 
      </div> 
     </div> 
     <div class="panel-txt-area"> 
      <p>blablablabla.</p> 

     </div> 
     </div> 
    </a> 
    </div> 
</div> 

jQuery函数:

$(".img-panel").hover(function(){ 
$(".panel-title-text").css("opacity","0"); 
$(".panel-txt-area").css("background-color","pink"); 
}); 

希望这有助于:)

+1

jQuery并不是所有需要的东西,如果你必须jQuery的一切,你可以很容易地在CSS中做到这一点,你可以得到很不好的习惯。 – Stewartside

+0

选择完全是你的问题:)。但我想jQuery提供了很少的代码和效率所需的效果,所以我建议。但正如我告诉最终决定完全是你的。 :);) –

+0

嗨,谢谢你的回复。不完全是我所追求的 - 我想要不止一个元素来改变它。 – SteveDavies

0

您将无法使用脱节翻转这样的CSS,只有JavaScript就能够看的状态另一个因素,并适用于其他条件等。如果它是它的孩子,当然它可以 - 下面演示了这一点。 您coud使用: -

.sm-gutter:hover, .sm-gutter:hover h3 span{ 
    background:purple; 
} 

难道这是使用替代,使用CSS的解决方案坚持?

+0

嗨杰米,我会如何恭维呢? – SteveDavies

+0

对不起,我不关注?你可以添加我提供给你的解决方案的CSS吗? –

+0

你需要删除其他悬停引用,以保持您的CSS清洁,并取消覆盖其他CSS呼叫的需要 - 请注意我用紫色,所以你可以看到它的工作。 –