I've got a friend, mrOverAbsolute, who wants to sit on top of another friend, mrAbsolute. Neither one seems to complain. I've got another friend, who responds to "mrHover" that wants to use a sprite. mrHover is only happy when the big dogs, mrHover and mrOverHover aren't so absolute.
Here's the drama:
<style>
div#mrOverAbsolute
{
z-index:1;
/* ... and some other stuff */
}
div#mrAbsolute
{
position:absolute;
z-index:-1;
/* ... and some other stuff */
}
a.mrHover
{
background:url('mrImage') 0 0;
}
a.mrHover:hover
{
background-position:0 25;
}
</style>
<div id="mrOverAbsolute"></div>
<div id="mrAbsolute">
<table>
<tr>
<td><a href="" class="mrHover"></a></td>
</tr>
</table>
</div>
Okay okay -- friends aside -- if I remove "position:absolute;", the sprite works. Otherwise, Chrome ignores the fact that I've declared a ":hover" in CSS.
Any suggestions?
Generally speaking, float is a relative positioning statement, since it specifies the position of the element relative to its parent container (floating to the right or left). This means it's incompatible with the position:absolute property, because position:absolute is an absolute positioning statement.
You might have linked your stylesheet to your HTML file improperly. Some other CSS in the context of your project may be overriding the piece that you've given here. You might be running into browser compatibility issues with the :hover selector or something else in your code that is breaking the styling.
Fixed positioning is really just a specialized form of absolute positioning; elements with fixed positioning are fixed relative to the viewport/browser window rather than the containing element; even if the page is scrolled, they stay in exactly the same position inside the browser window.
There is no problem with :hover
on absolutely positioned elements.
The problem is that you place the #mrAbsolute
element behind the #mrOverAbsolute
when you set its z-index:-1
so the mouse events are intercepted by #mrOverAbsolute
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With