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:

  1. Validate your HTML. Check your markup with the W3C HTML validator.

  2. Validate and check your CSS with the W3C online CSS validator.

  3. 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;
}

  1. Put a border around all block elements:

* {
 margin: 0;
 padding: 0;
 border: 1px solid red;
}

  1. Try different property values.

  2. 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.

  3. 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.

  

 

 

 

back to top