Forum Moderators: not2easy

Message Too Old, No Replies

<?xml version="1.0" encoding="utf-8"?>

Encoding alters page css

         

Jimmy Turnip

11:04 am on Feb 8, 2005 (gmt 0)

10+ Year Member



Why does adding <?xml version="1.0" encoding="utf-8"?> to the top of my document alter my css layout in IE? It seems to push one of my columns slightly to the right. Is this a known bug?

My page validates tentatively without the declaration, but would like it to validate properly. What is going on?

I know in .NET you can add the encoding declaration to the web.config, but is there a way with ASP or IIS to add this or even a CSS hack to fix the layout problem?

Hester

1:42 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having anything but the doctype on the first line triggers a bug in IE. It drops from Strict Mode to Quirks Mode. So even if you are coding strict XHTML, the effect is like earlier versions of IE, which got the padding wrong. Just remove the XML declaration and everything will be fine again.

I would also argue that the XML declaration is only needed if you are serving your pages as application-xml/xhtml, which as you may know, does not work in IE anyway (it tries to download the page!).

encyclo

1:57 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hester is correct that using the XML declaration is inappropriate when producing XHTML served with a
text/html
mime type - which means almost all XHTML documents.

The best was to declare the charset if you are using ASP is to add an HTTP header declaring the charset before the page is sent. I don't do ASP so I don't know the exact syntax, but I think it's something like this:

<%response.Charset="utf-8"%>

(See the MSDN documentation [msdn.microsoft.com])

If you're really stuck, you could also just use the old meta charset tag in the page head (but it's a compromise solution):

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Jimmy Turnip

2:11 pm on Feb 8, 2005 (gmt 0)

10+ Year Member



Cheers for the help - exactly what I was looking for.

Only the second site I've done to xhtml strict standard, but I didn't notice IE acting weird on the last site.

Thanks again.