views:

2027

answers:

19

Currently I am designing a website and I am finding it VERY difficult to display the website perfect on ALL browsers.

Is there any rules, suggestions etc to follow?

Thanks

+19  A: 

It is practically impossible to get a website to look exactly the same on all browsers and platforms. Number one reason is that fonts are rendered differently on Windows, Mac, Linux, Solaris, etc.

There is a new thought we follow: Websites do not have to look exactly the same on different browsers and platforms. You can take it to 96-98% of the way there very easily. The rest would take you an inordinate amount of effort for the potential gain.

We start development for Firefox. If we get that one right, the rest of the browsers are very close. IE is the real tricky one to get right most of the time. I recommend that you tell your client or yourselves that IE 6 is not really a requirement anymore.

Make sure you start off on the right foot by using a "reset" css stylesheet that puts all browser output on common ground. Check out: http://developer.yahoo.com/yui/reset/

Lastly, save yourself some trouble and standardize on a Javascript library like ExtJS or JQuery or Prototype that will conceal away the browser differences and let you concentrate on the code for your project.

Mike
I disagree. IE 6 is still a requirement. Since IE 7 is relatively new compared to 6, few major corporate customers have new PCs with Vista or even XP. Try telling a company that runs 1500 Win 2000 boxes that IE 6 isn't a requirement, and they'll tell you where the door is.
davethegr8
IE6 should indeed, how sad it may be, most of the times still be taken into account. (our lives would be so much easier if everyone would just use Firefox or Chrome)
Pim Jager
IE6 will not cease to be relevant until MS end-of-lifes enterprise support for XP. As it stands, it's still *vital* — even now, IE6 has a larger market share than all versions of Firefox combined. We may not like it, but we can't ignore it.
Ben Blank
There are, undoubtedly, businesses that still run 2000. But there are much more than "few" major corporations that run XP. In fact, due to the issues of support contracts expiring, most major corporations will *not* be running 2000 but XP.
Mike
@Ben Blank: IE7 runs on XP...
Mike
"IE 6 is not really a requirement anymore." The top 3 user agents we log are XP/IE7 (26%), Vista/IE7 (17%), XP/IE6 (15%) (not counting all the minor variations of IE UAs). Almost as many people are visiting our site with IE6 as IE7 on XP. So I'd suggest that it really depends on your audience.
Grant Wagner
I also get 15% of IE6 on non-tech websites.
Mauricio Scheffer
You might want to take the approach to IE6 as not having everything enabled. Think about the concept of Progressive Enhancement: Only enable something if the browser supports it. IE6 would be slightly less functional compared to the other browsers, but not to the point of being unusable.
Redbeard 0x0A
@Mike: Yes, but XP *ships* with IE6. The majority of the companies I've worked for (small and large) haven't been willing to push IE7 as a mandatory update, so until they adopt Vista, IE6 will have a large user base in the enterprise.
Ben Blank
A little over a year later: http://blogs.zdnet.com/Bott/?p=1645I restate it, IE6 is no longer a requirement.
Mike
+3  A: 

A lot of developer like to start testing with FireFox and go to IE7. This way they have both most popular browser.

I like to start with IE7 than go to FireFox because Firefox has this FireBug that let me see what's wrong and do the correction. But I have to say that I am changing slowly to test with FireFox fist since it does respect more all rules. (By the way, FireBug is available in Javascript for IE so it's great).

Of course, you should see who is your public. If it's internal used by the company and they only use IE... the choice is simple. If it's more for developer, you will have more user that will use FireFox... you might want to test first depending of your audience.

But, do not try to make it looks perfect on all browser, you will waste your time for nothing. Just make sure everything look ok and all javascript action are done correctly.

Daok
Check out "Internet Explorer Developer Toolbar".
Vilx-
Thx didn't know about it!
Daok
Also Web Development Helper (http://projects.nikhilk.net/WebDevHelper/)
Mauricio Scheffer
+2  A: 

Don't try to make every browser display it pixel-perfect the same as the others... only you will know! Just try to make it look good on every browser.

Greg
A: 

Using strict doctype, valid xhtml/html and valid CSS are good starting points. Also, make sure you use reset/undo.css.

In spite of all these, there would be catches but very few though

questzen
+2  A: 
  • You will never get perfection, go for the best you can get it.

  • Typically the best bet is to use subsets of css that work accross all browsers instead of browser specific hacks.

  • For javascript, be sure to use a javascript framework (JQuery / Prototype / YUI / Ext / etc), and use it exclusively for dom referencing/manipulation. It is hard to get that stuff right, and they have already done alot of the work for you

  • Good reference site

Matt Briggs
+3  A: 

I would suggest identifying your target audience, then identify which browser they use. Once you have done this, push for perfection in that browser. Now, you can do some work around and make it look good for the other browsers.

Targeting for perfection in all browsers today is similar to asking for world peace.

Another approach you can take is use a Javascript framework like jQuery to ease the pain.

+1  A: 

Develop for Firefox. Then apply IE-specific fixes. Hopefully, it'll render OK in Chrome and Safari.

The reason is that there are fixes available to make IE work 'properly' but not many to make Firefox behave badly.

Oh, and buy a copy of Transcending CSS.

Steve Morgan
Ordered the book you suggested right now! 10x
David Bonnici
+10  A: 
  • Make sure your XHTML and CSS validates.
  • Only use standard Javascript.
  • Test in one major (non-IE) browser: Firefox or Chrome would be my suggestion.
  • Your site should now look very close in major (non-IE) browsers
  • Test in something like dillo or lynx (or both)
  • Finally, start doing the hacks to make IE work
singpolyma
+1 for w3c validation - resolving validation errors can solve lots of layout differences
matt b
+1 for the validation as well! It truly does fix a lot of differences. Also, adding CSS styles that enable IE's hasLayout 'mode' of an element as you are working, you'll have to search the web on hasLayout, but things like adding `position: relative;` to an element enables hasLayout.
Redbeard 0x0A
I like "zoom:1" better, because it doesn't effect anything else than hasLayout.
I.devries
+2  A: 

I have discovered that using more CSS instead of tables makes it easier to get it the same on all the browsers. It's still a bit tricky, but table layout logics are worse. Use tables sparingly.

Oh, and getting things "stretchy" is always a problem. Fixed widths/heights are way easier.

Vilx-
+4  A: 

Here is an answer I gave a while ago about perfecting websites in browsers (from here)

Actually, what you need to use when developing a web application are:

  • FireFox
  • IE
  • Safari
  • (Chrome soon...)

And what I mean is that you should test every step of your website on all 3 major Grade-A browsers...so if something doesn't work in the process, you will know exactly what caused the break.

If you don't check regularly with the browsers on how your page is turning out, it will be a lot harder to fix problems later on.

Andreas Grech
+1  A: 

My approach is to code for firefox, opera, and the other non Microsoft browsers. Once it works in those, i patch up the IE functionality in a separate stylesheet/js file.

Also i usually use a JS library and a CSS framework. 9 times out of 10 i use Jquery and YUI Grids.

Jonathan
+7  A: 

Check out Browsershots. It makes screenshots of your sites with various browsers, so you can check it visually. It's kind of slow but it worked for me.

Drejc
+20  A: 

Develop to standards, then add exceptions

Currently, the most popular mostly-compliant browser is Firefox, so developing to Firefox is a natural first step. Use the W3C's validators to make sure you're on track. Once your page is mostly done, verify that it still looks good in Safari and Chrome (also both highly-compliant browsers, so you shouldn't have too much trouble), then start fixing it for IE (both 6 and 7). And believe me, it will need fixed! Sites like QuirksMode can be a big help when it comes time to add exceptions.

Always use the HTML 4.01 Strict DOCTYPE

This is probably going to be one of the more controversial points here, as XHTML has a lot of proponents. Unfortunately, it is impossible to serve XHTML files in a manner which is both IE-compatible and standards-compliant — IE won't recognize the XHTML MIME types, and it violates the standard to serve them as text/html. Only the HTML 4.01 Strict DOCTYPE puts all browsers into (near-)standards mode while still complying with the standards. For more info, look up DOCTYPE switching. If you absolutely can't get by without writing pages which are well-formed XML, use an XSL Transformation to convert your pages from the XML flavor of your choice into HTML.

Don't use CSS "hacks"

They can be very tempting sometimes, but hacks are based on the side-effects of browser bugs. Because of this, it can be difficult-to-impossible to predict how future browsers will react to them. Conditional comments, on the other hand, are an intentional feature of IE browsers and so are safe to use. In fact, they are an excellent way to keep your IE-specific (and often non-validating) CSS out of your valid stylesheets.

Don't create pixel-aligned layouts

Trying to get all browsers to line up, down to the pixel is an exercise in frustration (and, often, futility). Try to create layouts which still look okay when clobbered, as it's easier to fix a misalignment between, say, two left-hand borders than a left and a right which are on opposite sides of the page! Using a background image which has built-in borders should be a big warning flag!

Don't use absolute sizes for fonts

Not everyone uses the same size monitor as you do; instead of setting a footnote to font-size: 10px;, set it to font-size: smaller; or font-size: 80%;. This is a big acessibility issue.

Don't rely on default values for CSS properties

You never know whether all browsers use the same default. YUI's "reset" stylesheet is a great place to start.

Ben Blank
You have to keep in mind that ASP.NET 2.0 controls XHTML 1.0 and it is actually stated in MSDN that anything you output in ASP.NET 2.0 needs to be in XHTML 1.0
Redbeard 0x0A
Agree with all except HTML4. But it's better to use HTML4 than quirksmode.
singpolyma
I can't say I'm very familiar with ASP.NET — would it be possible to run the XHTML output through an XSL tranform before sending it to the browser? I've seen the identity transform used to "convert" XHTML to HTML… :-)
Ben Blank
A: 

I check website in FF etc first and then "repair" the site to look ok in IE. Mostly if the code is validated and clean and simple, IE needs only few small edits. I use different stylesheets for IE.I don't recommend using hacks.For javascript use only one library. And yes, browsershots help much.

perfectDay
What do you mean by "repair"? You will risking that the website will display properly on IR rather than FF....
David Bonnici
Well, no. I only change the code to display it properly on *either* IE + FF ++ ...or add new style properties for IE
perfectDay
+2  A: 

Use strict doctype.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

If you are using ASP.NET then you should add/change this is your web.config.

<system.web>
 <xhtmlConformance mode="Strict"/>

You should also check out the css compliant adapters. http://www.asp.net/cssadapters/

I have spent hours to make my website display the same across all the browsers and this seems to work. One last suggestion. Check often: don't do too much before you check to ensure all browser display it the same.

Bobby Cannon
Or XHTML1.1. A bit cleaner than 1.0 strict :)
singpolyma
I will have to check this out.
Bobby Cannon
A: 

Use a JS library, such as ExtJS. This abstracts away the browser-specific aspects of styling.

Is it wrong that it looks different in different browers, as long as it is legible and clean?

Doug Mulley
A: 

Use CSSViewer Extension for firefox, it could help to see some fixes you can do to the code very user-friendly. Use CSS display:block or display:inline-block properties, they are sooo usefull. Margin, padding, height and width will be your friends, sometimes you need to specify these values to see the same thing on many browsers. For fonts i would recommend you to read yahoo yui fonts css stuff.

+1  A: 

Okay the best way to follow is to use libraries and pre-written codes. For example : never use JavaScript, instead, use JQuery because it's compatible with all the browsers out there and instead of writing your own theme, use free css themes.

Well it works for me and help me save tons of time. Because on professional market, time means money.

Thanks.

Braveyard
Well actually it's not appropriate to say something "Never use javascript". But you can prefer to use JQuery-like-libraries to avoid cross browsers issues.
Braveyard
A: 

IE7 is no longer a requirement either. It is now a liability with its troubling security. IE8 should support most of what the other browsers do, and the bits it doesn't, don't matter. The experience will be degraded, but if you are using IE in the first place, you have no taste anyway.

Mike