The scenario is that I want to insert a number, which is placed in a <div>, over an image(z-index of image= -1).I have an image inside my anchor tag. I’ve found out the Top and Left positions of the anchor tag (id = PersonalInfo), then I’ve set the position of the <div> to fit in the center of the image.But the number shows somewhere on the extreme right of the browser window, and a little below the image. How do I get it in the proper position.
Also, I want to know how to get the top and left co-ordinates of any element with respect to the browser window’s borders (not including the toolbar at the top).
<a href='#' id='PersonalInfo' class='links' disabled='disabled' name='1' ><img src='../Images/COBreadCrumb/disabled.gif'></a>
The Jquery code I wrote for it is this:
var number = $("#PersonalInfo").attr("name");
var tag1 = "<font style='Verdana' size='3'>";
var tag2 = "</font>";
var content = tag1 + number + tag2;
$("#" + number).html(content);
var LinkTop = $("#PersonalInfo").offset().top;
var LinkHeight = $("#PersonalInfo").height();
var NumberTop = LinkTop + (LinkHeight / 2);
var NumberLeft = $("#PersonalInfo").offset().left + ($("#PersonalInfo").width() / 2);
$("#" + number).offset({top:NumberTop,left:NumberLeft});
The div tag:
<div id="1"></div>
Becase Richard beat me to the punch, and as bazmegakapa points out, the table-cell trick is fail in IE7, here’s another solution: