views:

163

answers:

7

Am building a website using Django, my templates make use of CSS and am testing it locally using firefox, but when i was just about to "show it of" to my buddies i run it against IE and the darn web site is all broken! the headers are all messed up nothing seems to hold together, the spaces are all messed up! its bad.

Is there something am missing! like some header declaration? DOCTYPE or something?

NB: I grabbed the css am using from some site in the internet, and when i run that site on IE it all looks good!

Help

This is the offending css, the h1 section that is using this css is the one that is breaking, any clues?

div#header
{
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 10px;
  text-align: left;
  width: 780px;
  height: 102px;
  background: url(/site_media/header_background.gif) no-repeat top left;
}


div#header h1
{
  padding: 30px;
  font-family: Verdana, sans-serif;
  font-size: 17px;
  font-weight: bold;
  color: #c8c8c8;
  letter-spacing: -1px;
}

div#header h1 strong
{
  color: #999;
  width: 810px;
}
A: 

This won't help you this time, but next time you develop a site "from scratch", try testing the site in IE at least once every day. That way you will not get this kind of surprise at the end.

If you want a more precice answer, post the URL and someone will point out why it looks different in IE and Firefox

Espo
Am still testing it locally!
gath
+1  A: 

You're not missing anything. Welcome to IE...

Most of the problems are likely to be caused by bugs in IE's rendering engine. These links might help:

You can include an alternate version of your stylesheet for IE using conditional comments in your HTML.

Steve

Steve Harrison
A: 

This is my PHP function I use to determine the appropriate stylesheet:

    function stylesheet() {
 $ua    = $_SERVER["HTTP_USER_AGENT"];
 $iepos = strpos($ua,"MSIE");
 if ($iepos) {
  $vers = substr($ua,$iepos+5,1);
  if ($vers >= 8) return "style.css";
  else return "iestyle.css";
  }
 else return "style.css";
 }

I was having a really odd problem where I needed IE8 to be the "good" version, so most people can probably change...

if ($vers >= 8)

to...

if ($vers >= 7)

Then I just have, in place of a normal CSS link:

<?php echo "<link rel=\"stylesheet\" href=\"".stylesheet()."\" />"; ?>

Good luck.

Shadow
I'm not really sure browsing sniffing is the way to go here, especially not the way you're suggesting. See here: http://www.howtocreate.co.uk/tutorials/jsexamples/sniffer.html and http://www.quirksmode.org/blog/archives/2006/08/the_dangers_of.html for some discussion of it. This is especially difficult to maintain when you can theoretically support 3 versions of IE, plus all others. If you want to serve something to IE only, use conditional comments.
Nick Presta
+3  A: 

First, make sure you're using a document type declaration that does not trigger Quirks Mode. I suggest HTML 4.01 Strict, or XHTML 1.0 Strict.

Second, make sure your site validates according to the W3C validator.

Finally, post the site in question, or a snippet of what is wrong, so we can advise you further. You may need conditional CSS specifically for (versions of) IE.

EDIT: Now seeing your update, could you post a screenshot of what you consider 'broken' and can you make sure the page is NOT using that transitional doctype and that it validates. The accompanying HTML would be helpful as well.

Nick Presta
XHTML 1.0 Strict will only not invoke quirks mode if the page is served with the mimetype text/xml rhather than text/html
ck
+1  A: 

Try to use reset.css file for more "happy" cross browsing. You can see a detailed information about reset.css from Eric Meyer's site. Also there is another reset.css file which has developed by one of the developers of yahoo. But result is same for both reset.css. You can try any of them.

Enes
Please don't.We rely on the default styles and resetting the css is usually more work than it saves. And it won't help make ie any more standards compliant - so it wont help his issue.
SamGoody
It works fine to me. It saved a lot of time of mine, but of course it is a choice. Whatever you choose, it is important to feel comfortable when you are coding. Thanks for the comment.
Enes
A: 

and then once you've got your website happy on IE7, you'll probably need to confront all the additional problems that IE6 will still have with it. IE6 still runs on about 15% of PCs so you'll have to decide what you wanna do about that...

Oh and don't forget your Safari, Chrome, and FF2 testing. :)

Scott Evernden
A: 

For the doctype, the primary purpose is to get the browser out of quirksmode.

You can use theirs

<!DOCTYPE XHTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

or even just

<!doctype>

Which is the HTML5 doctype, and is simpler :) [Though it will give different errors if you use the w3c validator to check your code.]

What is most definitely messing you up is the padding:

div#header h1 { padding: 30px; ...

IE has a, er, different box model than the other browsers and the first thing to show it are the borders and paddings. (In IE the width includes the padding, in other browsers it doesn't)

To solve this you can use IE conditions or hacks to give IE its own styles, or you can use nested divs to and margins, which are treated more consistently. You can also use Dean Edwards IE7 or similar to fix it using Javascript.

SamGoody