views:

115

answers:

5

hi all what basic tips should we observe in design web pages(html/css/javascript) for having highest compatibility with most browsers(IE-firefox-opera-chrome-safari)?

thanks

+7  A: 
  • Validate often and squash all validation errors by the time you make a public release. The purpose of validation, after all, is to parse the html as a standards-compliant browser would and then avoid the errors that a browser's parser would find.

  • Apply progressive-enhancement techniques. Often that means moving some of the complexity of dynamic pages to the back-end (e.g. php, django, what have you) so that you can have complex functionality that doesn't break in one of the thousands of different client environments in which a page's javascript will run. jQuery is excellent for narrowing the focus of your javascript development towards feature enhancement instead of open-ended features-in-javascript, and it'll help with cross-browser compatibility as well.

  • IE - Test in at least one live version of IE 7 or 8. Unfortunately, there really isn't any way around this, because even IE8 misbehaves like no other browser. If possible, limit your goal of support for IE6 to html/css (i.e. don't promise support for user-enhancement-features via javascript in ie6). If possible, drop support for IE 5.5 and below.

Tchalvak
I'd add just one thing: look at your page in IE6 using IETester before you launch and fix obvious problems. IETester link: http://www.my-debugbar.com/wiki/IETester/HomePage
Summer
+3  A: 

For Javascript, use libraries that are intended on being platform-independent (ie: JQuery, Prototype). Not everything will be, but it'll make your life much easier.

For CSS, I'd say follow standards, but IE tends to cause problems across the board.

Which means, you need to test, and test often. Selenium is awesome for automated functional testing, and it works with pretty much every browser. We use a Selenium RC server on a Windows machine to test IE and Firefox, which are then controlled from our standard Java JUnit tests.

Milan Ramaiya
A: 

Take a look at this great article: Browser Compatibility Tutorial

Remember: something won't just work for a specific browser (mayble a left dotted border won't show in Chrome). Do not be upset about that if you can! :) Cross-compatibility is an art that takes a lot of time.

Leniel Macaferi
In my experience, #1 won't help you, ignoring #2 when it comes to css won't hurt you, and #3 won't save you (you won't be able to avoid having an installed version/versions of IE, if only just in a virtualmachine). *shrugs*
Tchalvak
+1  A: 

Keep things simple.

The simpler your markup, CSS, and JavaScript, the easier it will be to track down incompatibilities. Try to limit yourself to CSS1 for as much as possible. Only use more modern CSS2/3 features when there is no easier way to accomplish your task.

Don't use tables, they just add extra complexity. Using semantic markup not only makes things maintainable, but also gets you the best cross browser support if done properly.

Keep in mind that floats are evil, but are also very powerful. Use them generously, but avoid trying to clear floats. Use overflow instead.

Use a JavaScript framework. Framework developers have smoothed out most of the cross-browser bugs for you. I recommend jQuery, but you can choose any framework your developers feel comfortable with. My advice is to:

  • Use a JavaScript framework that doesn't alter the prototypes of native objects (like Prototype JS does)
  • Doesn't introduce many global variables. Most frameworks follow this rule.

Aside from those 2 rules for JavaScript, try using closures to encapsulate code so you don't introduce your own global variables.

Dan Herbert
Mostly good advice, though I don't see using more modern css as a bad thing, less capable browsers should just ignore it, so you just have to make sure that the use of more modern css is just for enhanced features/presentation.
Tchalvak
@Tchalvak Though you're correct and most of the time it shouldn't an issue, there are situations where relying on newer CSS features can cause a layout to not work in older browsers. For example, the CSS Template Layout feature (once implemented) absolutely won't work in older browsers and will cause layouts to completely break. http://www.w3.org/TR/css3-layout/
Dan Herbert
A: 

One strategy I use is to start my CSS with a set of rules that blank everything out. Each browser may have different values for element attributes so ensuring that everything is consistent from the get-go can be handy. Here is an example reset.css http://meyerweb.com/eric/tools/css/reset/

darren
Not sure how well that is maintained, so I recommend blueprintcss ( http://github.com/joshuaclayton/blueprint-css ), which is continually being fixed and updated as the landscape changes. Just take out the parts that you don't expect to need, since the size runs large.
Tchalvak