how do you center a div in the center of the page using CSS?
Printable View
how do you center a div in the center of the page using CSS?
You can't use CSS to do this. However this JavaScript should help:
function centerDiv(objName){
var trueLen;
var thisObj = document.all(objName);
trueLen = thisObj.style.width.substring(0,thisObj.style.width.length-2);
thisObj.style.left = (document.body.clientWidth / 2) - (trueLen / 2);
}
call it as in centerDiv("objectname").
Well, as I just found out, there isn't a way to tell an element to center itself, you can just tell it to center it's contents.
Create a div to hold your div. Tell the outer one to have a 100% width.
and.......?
align:center doesn't work
try text-align.
cool, that worked
is the <center> tag standard HTML?
Yup.
<center> is depreciated, though -- you're supposed to use css nowadays -- separate presentation from content.
k, thats what i thought. thanks