Click to See Complete Forum and Search --> : Layer Centering Question


TurtleEKH
March 19th, 2003, 05:39 PM
I want to have a layer set to be centered on a page based on browser size,. i.e. the layer will be centered within the browser regardless of whether it is being viewed on a laptop or on a 21 inch monitor. Any thoughts on a simple way to do this?

nategrover
March 19th, 2003, 08:03 PM
Try this in IE. not sure about the other browsers, but you can check out the API for them on their websites.

var theDiv = document.getElementById("myDiv");
theDiv.style.position = "absolute";
var px = theDiv.offsetWidth/2;
theDiv.style.left = (window.document.body.offsetWidth / 2) - px;