CSS3 Position Fixed centering problem

Source: Internet
Author: User

Typically, we want to center an element and do this:

#element {margin:0 Auto;}

What if you want to fix this element position? Generally we will add position:fixed, as follows:

#element {position:fixed;margin:0 Auto;}

But the result is that the element is not centered. This indicates that the fixedthe object is out of normal document flow.

Solution:

#element {position:fixed;margin:0 auto;left:0;right:0;}

However, you will not be able to work in a version below IE7 to change it to:

#element {position:fixed;margin:0 Auto;left:auto;right:auto;}

Finally we can do this:

if ($.browser.msie && parseint ($.browser.version) <= 7) {    stralertwrapper.css ({position: ' fixed ', Bottom: ' 0 ', Height: ' Auto ', left: ' Auto ', right: ' Auto '}; }
Example code: http://jsfiddle.net/4Ly4B/33/
If it is helpful to you, welcome to join: QQ Group:124116463, discuss the front-end technology together!






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.