<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><style>#box1{width:200px;Height:200px;padding:100px;Border:1px solid Black;position:Absolute;Top:0; Left:0; Right:0;Bottom:0;margin:Auto; }H1{text-align:Center;}</style></Head><Body><DivID= "Box1"><H1>I want to center.</H1></Div></Body></HTML>
Both of these methods allow a box to be centered in the browser window.
The first method: set absolute positioning first, and both top and left values are set to 50%. Then set the box's margin-top to half the height of the box, Margin-left set to half the width of the box ( Note that the values are negative ).
The second method: Also through absolute positioning, but here the value of Top,right,left,bottom is set to 0, and then set the Marign:auto. The box is naturally centered.
CSS Learning notes box centered