5 reasons to avoid CSS hacks and conditional stylesheets

Source: Internet
Author: User

Http://www.sitepoint.com/blogs/2009/03/05/5-reasons-to-avoid-css-hacks-and-conditional-stylesheets/

SS is more of an art than a science. you can know about every combination of selector and be an expert in every styling property, yet still be unable to lay out and style your website as you want.

There are several reasons why developers from traditional programming backgrounds dislike CSS:

  1. Learning the rules is only half the game-you need experience to really understand CSS.
  2. CSS can be illogical and require too much trial and error.
  3. Even if browser x renders your page perfectly, browser y cocould fail dramatically.

Your web sites and applications are considered complete only to find that it breaks in a certain browser. Web developers therefore resort to hacks and conditional CSS to fix the issues as quickly as possible.

Unfortunately, quick-fix development can cause more problems in the long run...

1. CSS validation may not be possible
There are using tools, such as the Firefox console and the W3C validation service, that help developers find errors within CSS code. unfortunately, hacks and conditional stylesheets often rely on invalid CSS to exploit a known browser bug or apply vendor-specific properties. if your CSS is already throwing errors, you may miss the real problems.

2. Your CSS becomes more complex
Quick fixes generally apply further rules to your existing rule set. in the case of conditional CSS, those rules will also be in a separate file and only apply under certain conditions. whilst tools such as firebug can help locate and analyze the code, they are not available in every browser. the increased complexity makes debugging and maintenance more difficult.

3. Your CSS may not be future-proofed
Hacks rely on browser bugs. Unfortunately, the next version of that browser may fix the very bug you depended on. This was certainly one of the causes of IE6-compatible sites breaking in IE7, e.g..* htmlSelector was incorrectly applied by IE6 but fixed in ie7.

If your website already relies on IE6 and IE7 conditional stylesheets, it is extremely likely you will require one for ie8.

4. It is browser Detection
Webpages shoshould be device-independent. whilst we do not live in an ideal world, browser detection always feels a little dirty. it is certainly avoided in JavaScript and server-side code, so why use it for CSS?

5. There is rarely a need for them
It is unusual to find a design that cocould not be created by an experienced Coder Using standard CSS that works in all the popular browsers (and, yes, that could des IE6 ). minor rendering differences are always inevitable, but the CSS code can remain clean and valid for all browsers.

Ultimately, hacks and conditional CSS can lead to poor development practices and a failure to diagnose or understand the real problem. the key is to test early and test often: Find the issues at the start of the project and you will not need to resort to quick fixes at the end.

Don't believe me? See 10 fixes that solve IE6 problems...

Have you successfully avoided hacks and conditional CSS or have they been essential within every project?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.