2015-07-21 637 views
1

我的博客准备的布局和需要制作幻灯片或多或少如下当激活叠加背景:悬停在链接

enter image description here

我已经能够通过CSS做很多,但我有一个问题!只有当鼠标悬停在div上时,图像才会激活,但当需要将图像悬停在图像链接上时,需要激活图像或更好地将其着色。

有人可以帮我解决这个问题吗?

就拿我的代码通过BOOTPLY

Bootply

我不知道如果我这样做,通过CSS或仅通过JavaScript。我甚至试图通过JavaScript做更多的事情,但对此并不了解。

回答

2

您需要在图像和文本的父级上使用伪类:hover。当您将鼠标悬停在该元素的任何子元素上时,这将改变图像的不透明度。

更改此

.img-box-feature:hover{opacity:1;} 

这个

[class*="box-"]:hover .img-box-feature{opacity:1;} 

See updated Bootply

另外,我建议你从box-umbox-dois改变类和box-tres只是box。然后,您可以使用.box:nth-child().box:nth-of-type()来定位特定的一个。

1

如果改变这一行:

.img-box-feature:hover { 
    opacity:1; 
} 

这样:

.img-box-feature:hover, 
.img-box-feature.hover{ 
    opacity:1; 
} 

,你可以使用jQuery来切换到新的类:

$('.over-text-feature h1 a').on('mouseenter mouseleave', function(e) { 
    $(this).closest('[class^="col-"]').find('.img-box-feature').toggleClass('hover'); 
}) 

Bootply

0

TR y out webkit filters

例如,您可以使用对比度(%),亮度(十进制),模糊(px)或棕褐色(%)。

+0

这里与转化和深褐色施加bootply http://www.bootply.com/lgE3WwzWaC –

0

如果你想让图像激活也可以将悬停在文本上,或者只有将鼠标悬停在文本上时,它仍然不清楚。我也想知道你是否想所有图像被激活到只有一个

如果您想所有的图像徘徊在文本时变得活跃,你可以移动文本元素是.section-slider的第一个孩子,并使用CSS兄弟选择:~

像这样:

<section class="section-slider"> 
    <div class="over-text-feature"> 
    <h1><a href="#">Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos</a></h1> 
    <p>Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos</p> 
    </div> 
    <div class="container"> 
    <div class="row"> 
     <div class="col-md-6 box-um"> 
     <div class="img-box-feature" style="background-image:url('http://lounge.obviousmag.org/a_boleia_da_ideia/2012/08/gatimonias-ou-maldita-curiosidade.html.jpg?v=20150627141437')"></div> 
     </div> 
     <div class="col-md-6 box-dois"> 
     <div class="img-box-feature2" style="background-image:url('http://lounge.obviousmag.org/a_boleia_da_ideia/2012/08/gatimonias-ou-maldita-curiosidade.html.jpg?v=20150627141437')"></div> 
     </div> 
     <div class="col-md-6 box-tres"> 
     <div class="img-box-feature2" style="background-image:url('http://lounge.obviousmag.org/a_boleia_da_ideia/2012/08/gatimonias-ou-maldita-curiosidade.html.jpg?v=20150627141437')"></div> 
     </div> 
     <div style="clear: both;"></div> 
    </div> 
    <div class="row"> 
     <div class="col-md-3">01</div> 
     <div class="col-md-3">01</div> 
     <div class="col-md-3">01</div> 
     <div class="col-md-3">01</div> 
    </div> 
    </div> 
</section> 
/* SLIDER PRINCIPAL */ 
.section-slider{ background:#000; width: 100%;} 

.img-box-feature{ 
    width: 100%; 
    height: 0; 
    padding-bottom: 70% ; /* % of width, defines aspect ratio*/  
    background-repeat: no-repeat; 
    background-position: center center; 
    background-size: cover; 
    background:rgba(0,0,0,0.6); 
    opacity:0.3; 
    transition: all 0.5s ease; 
    -webkit-transition: all 0.5s ease; 

} 
.img-box-feature2{ 
    width: 100%; 
    height: 0; 
    padding-bottom: 35% ; /* % of width, defines aspect ratio*/  
    background-repeat: no-repeat; 
    background-position: center center; 
    background-size: cover; 
    background:rgba(0,0,0,0.6); 
    opacity:0.3; 
    transition: all 0.5s ease; 
    -webkit-transition: all 0.5s ease; 
} 
.over-text-feature{ z-index:100; 
    position:absolute;  
    color:white; 
    display: inline-block; 
    vertical-align: middle; 
    bottom: 15px; 
    width: 95%; 
    left:10px; 
    border-left: 5px solid #fff; 
    padding-left: 10px; 
    } 
.over-text-feature h1{ font-size: 1.8em;} 
.over-text-feature h1 a{color: #00aeef;} 
.section-slider .box-um{float: left; margin: 0px !important; padding: 0px !important;} 
.section-slider .box-dois{float: right;margin: 0px !important; padding: 0px !important;} 
.section-slider .box-tres{float: right; margin: 0px !important; padding: 0px !important;} 
.over-text-feature:hover ~ .container .img-box-feature, .over-text-feature:hover ~ .container .img-box-feature2{opacity: 1;}