How to overlay one div over another div

#container { width: 100px; height: 100px; position: relative; } #navi, #infoi { width: 100%; height: 100%; position: absolute; top: 0; left: 0; } #infoi { z-index: 10; } <div id=”container”> <div id=”navi”>a</div> <div id=”infoi”> <img src=”https://appharbor.com/assets/images/stackoverflow-logo.png” height=”20″ width=”32″ />b </div> </div> I would suggest learning about position: relative and child elements with position: absolute.

Retrieve the position (X,Y) of an HTML element

The correct approach is to use element.getBoundingClientRect(): var rect = element.getBoundingClientRect(); console.log(rect.top, rect.right, rect.bottom, rect.left); Internet Explorer has supported this since as long as you are likely to care about and it was finally standardized in CSSOM Views. All other browsers adopted it a long time ago. Some browsers also return height and width properties, though … Read more