Position:fixed and margin:0 auto not working in IE

亡梦爱人 提交于 2019-12-12 01:36:05

问题


I have coded a website in HTML and CSS.

In this website I have used both properties margin: 0 auto and position:fixed on several occasions.

The problem is that the website is correctly displayed in any modern browser except for IE 8+.

Another problem that I found is that there should not be a space between the header and the browser window. Again this only happens with IE.

This issues are usually related with the quirks mode of IE. However in this case I set the doctype correctly <!DOCTYPE html>

The link to the website so you can check this out is: http://juancarlosoleacañizares.es/index.php?page=0

I would prefer a solution without using JavaScript.


回答1:


There are non space characters before your doctype. The doctype should be the very first thing in the document. Because of this IE thinks the meta tags and others head elements are inside your body.

You can see this if you open the Developer tools (F12) in IE9.

The w3 validator would have told you too. Apparently it is a byte order mark (BOM), which should be omitted.

It's a good thing to learn to use these tools. They're essential for debugging problems like this.



来源:https://stackoverflow.com/questions/7422619/positionfixed-and-margin0-auto-not-working-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!