Reputation: 2763
I have a HTML as below:
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="span7">
<div class="home-image left-image">
<img class="photography-left-top" src="http://placehold.it/700x440" />
<p class="image-text_left">Wedditng Photography</p>
</div>
<h5>Heading</h5>
</div>
<div class="span5">
<div class="home-image right-image right-image-top">
<img class="photography-right-top" src="http://placehold.it/400x200" />
<p class="image-text_right-top">Fashion Photography</p>
</div>
<div class="home-image right-image right-image-bottom">
<img class="photography-right-bottom" src="http://placehold.it/400x200" />
<p class="image-text_right-bottom">Contact</p>
</div>
<h5>Heading</h5>
</div>
</div>
</div>
And the CSS :
.home-image {
position:relative;
}
.photography-left-top,.photography-right-top,.photography-right-bottom {
position : absolute;
}
.image-text_left {
display:none;
position:absolute;
width:300px;
top:200px;;
left:200px;
z-index : 100;
font-weight:bold;
}
.image-text_right-top,.image-text_right-bottom {
display:none;
position:absolute;
width:300px;
top:100px;
left:100px;
z-index : 100;
font-weight:bold
}
.right-image-bottom {
margin-top:220px;
position:relative
}
.right-top {
position:relative
}
.home-img-hover {
background:#911717;
}
JS :
$(document).ready(function(){
$(".left-image").hover(function () {
$(this).find('.photography-left-top').fadeTo('slow',0);
$(this).addClass('home-img-hover');
$('.image-text_left').show();
},
function () {
$(this).find('.photography-left-top').fadeTo('400',1.0);
$('.image-text_left').hide();
});
Since addClass('home-img-hover')
will add the a class to current class
I was expecting a background color when I hover on left-image
. But its showing white default background . Why ?
Upvotes: 0
Views: 140
Reputation: 12032
Here is your problem, your div's height is actually 0px
.
Just add
height: 240px;
width: 400px;
to the .home-image
class, and you'll see that your code actually works.
See updated JSFiddle
Upvotes: 2
Reputation: 36794
It does exactly what you're expecting, you just can't see it because the .home-image
doesn't have a height, because everything inside it is taken out of the normal document flow (with position:absolute
). Try giving .home-image
some dimensions, and you'll see what I mean:
.home-image {
position:relative;
width:400px;
height:240px;
}
Upvotes: 2