First look at the effect:
Http://www.keleyi.com/keleyi/phtml/fixedcenter.htm
KeyCodeYes: # topmenu_keleyi_com {position: fixed; left: 0px; Right: 0px; width: 706px; margin-left: auto; margin-Right: auto ;}
Complete code:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" > < Head > < Title > Center The position: Fixed div-ke leyi </ Title > < Style Type = "Text/CSS" > # Topmenu_keleyi_com { Position : Fixed ; Left : 0px ; Right : 0px ; Width : 706px ; Margin-left : Auto ; Margin-Right : Auto ; Top : 100px ; Height : 50px ; Background-color : Red ; } # Topmenu_keleyi_com Li { Float : Left ; List-style : None ; Margin-Right : 1px ; Width : Pixel PX ; Background-color : # E0f0e0 ; } # Topmenu_keleyi_com ul { Margin : 0px ; Padding : 0px ; } Body { Margin : 0px ; } </ Style > </ Head > < Body > < Div ID = "Topmenu_keleyi_com" > < Ul > < Li > < A Href = "Http://www.keleyi.com/menu/net" Target = "_ Blank" > . Net </ A > </ Li > < Li > < A Href = "Http://www.keleyi.com/menu/javascript" Target = "_ Blank" > Javascript </ A > </ Li > < Li > < A Href = "Http://www.keleyi.com/menu/jquery" Target = "_ Blank" > Jquery </ A > </ Li > < Li > < A Href = "Http://www.keleyi.com/menu/csharp" Target = "_ Blank" > C # </ A > </ Li > < Li > < A Href = "Http://www.keleyi.com/menu/other" Target = "_ Blank" > Others </ A > </ Li > < Li > < A Href = "Http://www.keleyi.com /" Target = "_ Blank" > Homepage </ A > </ Li > </ Ul > < BR /> Position: The Center effect of the fixed Div. Change the page width. </ Div > </ Body > </ Html >
This article Reprinted from Ke leyi: http://www.keleyi.com/a/bjac/326830ffb40fada9.htm