Many students fix the top menu, use postion: fixed, and then use margin: 0 auto to center, and find that margin: 0 Auto does not work.
Generally, we need to center an element in the middle, and we will do this:
#element{margin:0 auto;}
What if I want to fix this element? Generally, position: fixed is added as follows:
#element{position:fixed;margin:0 auto;}
However, the result is that the element is not centered. This indicates that fixed disconnects the object from the normal document stream.
Solution:
#element{position:fixed;margin:0 auto;left:0;right:0;}
However, it cannot work in IE7 or earlier versions. You need to change it:
#element{position:fixed;margin:0 auto;left:auto;right:auto;}
Finally, we can:
if ($.browser.msie && parseInt($.browser.version, 10) <= 7) { strAlertWrapper.css({position:‘fixed‘, bottom:‘0‘, height:‘auto‘, left:‘auto‘, right:‘auto‘}); }