Reputation: 131
Div
containaer and p
element overlapping another Div
that contains an image that needs to respond to a :hover
CSS event causing only a small portion of that Div
container to be able to sense the mouse hovering over it.
z-index
isnt effective for some reason either.Upvotes: 0
Views: 104
Reputation: 14308
As @colandus said adding the position: relative
and the z-index
to the img
should indeed do the trick.
However, it seems to me like you are over complicating things a bit. Why the position relative on the p
? that is the one that is causing the problem...
What you are trying to do is default behavior if you use some simpler html / css. Something like this:
the HTML with some div's removed:
<div class="insp">
<h3>Thomas Edison</h3>
<img src="http://www.placehold.it/250x150">
<p>Lorem Ipsum is s...</p>
</div>
and the css with the position: relative
removed from the p
:
.insp {
border: 2px solid black;
margin: 10px 0px;
padding:10px;
}
.insp h3 {
margin-top:0px;
background-color:#FFDE5C;
}
.insp img {
float:left;
border: 5px solid #FFDE5C;
height:150px;
margin: 0 20px 20px 0;
}
.insp img:hover {
border: 5px solid #ffffff;
}
.insp p {
margin: 40px 40px 40px 80px;
}
And as you can see (http://jsfiddle.net/7fvcD/4/), it looks exactly the same and there is no hover issue anymore.
Upvotes: 4
Reputation: 17368
Add the following CSS:
.insp-image img {
position: relative;
z-index:1000;
}
Don't need to change your markup ;)
Upvotes: 1
Reputation: 2080
Try this approach: Put the <div>
with the <img>
inside the <p>
tag and set some margin to the img div.
Upvotes: 0