XML technologies / CSS / CSS Cookbook / Hacks, workarounds and troubleshooting / Diagnosing CSS errors and browser problems
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to determine whether a display problem comes from your code or the browser’s rendering.
Solution
Follow these steps in order to identify possible problems in your CSS code:
Validate your HTML. Check your markup with the W3C HTML validator.
Validate and check your CSS with the W3C online CSS validator.
Simplify property values. Add at the end of the stylesheet or stylesheets a new CSS rule. The universal selector lets you define properties for every element at once:
* {
margin: 0;
padding: 0;
}Put a border around all block elements:
* {
margin: 0;
padding: 0;
border: 1px solid red;
}Try different property values.
Comment out the CSS rules where you suspect the problem. Then remove the comments one by one until the problem reappears. For information on CSS comments, see the recipe Comments in CSS code.
Search Google and positioniseverything.net, a thoroughly documented collection of CSS bugs, for similar problems.
Discussion
In my experience, about 90% of errors in CSS-based designs are caused by typos in CSS syntax or incorrectly formatted markup.
Following the steps in this recipe gives you a good chance of finding the source of the error.
See also
Read CSS – Das umfassende Handbuch by Eric A. Meyer (O’Reilly) to learn more about the CSS specification.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln