I can't think of a clean (or even hacky) way of doing this with CSS only. Here's the Javascript method if you don't see anything else. Just click mousemove
on body
.
function isOver( element, e ) { var left = element.offsetLeft, top = element.offsetTop, right = left + element.clientWidth, bottom = top + element.clientHeight; return ( e.pageX > left && e.pageX < right && e.pageY > top && e.pageY < bottom ); };
Demo: http://jsfiddle.net/ThinkingStiff/UhE2C/
HTML:
<div id="parent"></div> <div id="overlap"></div>
CSS
#parent { border: 1px solid red; height: 100px; left: 50px; position: relative; top: 50px; width: 100px; } #overlap { background-color: blue; border: 1px solid blue; height: 100px; left: 115px; position: absolute; top: 130px; width: 100px; z-index: 1; }
Script:
document.body.addEventListener( 'mousemove', function ( event ) { if( isOver( document.getElementById( 'parent' ), event ) ) { document.getElementById( 'parent' ).innerHTML = 'is over!'; } else { document.getElementById( 'parent' ).innerHTML = ''; }; }, false ); function isOver( element, e ) { var left = element.offsetLeft, top = element.offsetTop, right = left + element.clientWidth, bottom = top + element.clientHeight; return ( e.pageX > left && e.pageX < right && e.pageY > top && e.pageY < bottom ); };
ThinkingStiff
source share