XML technologies / CSS / CSS Cookbook / Lists / Cross-browser indentation

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

Browsers use different methods to indent lists. Left margins should provide a consistent appearance in all CSS-capable browsers.

Solution

Set the element ul to use values for the properties margin-left and padding-left:

ul {
 margin-left: 40px;
 padding-left: 0px;
}

Discussion

Browsers use different methods to indent a list. Mozilla and Netscape 6+ control indentation using the property padding (padding). Internet Explorer and Opera instead use margin (margin).

For a consistent appearance across browsers, explicitly set values for both properties. Define the indentation itself using only one of them. Splitting indentation between both properties causes inconsistent rendering across browsers.

If you set both properties to zero for a list directly descended from the element body, the browser may display list markers outside the visible area. To ensure that users see them, set either left padding or left margin for elements ul to at least 1em.

See also

  

 

 

 

back to top