Setting rather than Resetting Default Styling

In: web resources

11 Mar 2010

Future of Web Design London 2010

Editors Note: In his first article for Think Vitamin Thierry Koblentz discusses the issue of “resetting” your CSS.

“base.css” versus “reset.css”

For a long time, the very first line in my styles sheets was:

* {padding:0;margin:0;}

This simple rule was very convenient as it leveled margin and padding values of all elements across browsers. This “hard reset” was short and simple and it had the advantage of belonging to the main styles sheet rather than being an external file.

Later, this technique was denounced as bad practice as it makes the rendering agent style (check) every single element in a document. It also triggered issues with form controls, but authors were used to specifying styles for these.

Then came “reset” styles sheets. These files go way beyond resetting margin and padding. The most complete in terms of properties/elements involved has to be Eric Meyer’s. It “unstyles” everything you could think of, from a to var.

Authors start with a clean slate. From there, they most often write rules to style elements that were originally styled by the browser’s styles sheet, but overwritten by the reset file. In short, many elements are styled three times:

  1. by the browser’s styles sheet (see User Agent Styles Sheets).
  2. by the “reset” file.
  3. by the author’s styles sheet.

Criticism of this Approach

Jonathan Snook, Jens Meiert and others have “criticized” this approach, saying more or less that there was no use for a “middle man”. On Jen’s site, “randomCommenter” summarizes the issue pretty well when asking: “Wouldn’t a well written base style sheet render a reset style sheet redundant and therefore useless?”

Actually, I believe Eric Meyer himself hints in that direction when he says:

“I don’t particularly recommend that you just use this in its unaltered state in your own projects. It should be tweaked, edited, extended, and otherwise tuned to match your specific reset baseline. Fill in your preferred colors for the page, links, and so on. In other words, this is a starting point, not a self-contained black box of no-touchiness.”

In any case, people should at least evaluate the rules in these reset files before copying and pasting their content. For example, if one authors documents as HTML 4.01 Strict! one may safely remove from a reset styles sheets any reference to elements like:

  • iframe
  • applet
  • strike
  • u
  • font
  • s
  • center

My Base Styles Sheet

Following the idea of “tweaking” a reset file, I came up with this “base styles sheet“. It sets default styling for many elements, follows a couple of recommendations regarding usability/accessibility, and addresses a few “common issues” as well.

What does it do that a reset doesn’t?

It fixes a few things

  • It forces a gutter for a vertical scrollbar (when content is too short to require a scrollbar)
  • It includes an IE button width fix
  • It removes “sticky” outline (not in Internet Explorer though)
  • It prevents “mysterious gaps below images
  • It prevents descenders letters in legend from being cut-off in Internet Explorer
  • It vertically aligns checkboxes and radio buttons with their label
  • It sets a default color background for the document with no shrink wrap effect on body1

It styles lists by default

It is easier to remove markers on lists than to style them. So, by default, lists are styled to show indentation and markers depending on hierarchy and list types. But the styles sheet contains a class to reset this styling. When applied to a UL or OL – it will remove markers and left margin on their items.

It creates vertical “gutters”

Left and right padding are applied to most block-level elements to create vertical gutters. This allows to build layouts without having to use “padding” on main containers which helps to produce designs that do not break in IE 5 (or IE 6 in quirks mode) as width and padding values are not mixed. This is also an alternative to using non semantic wrappers as a workaround to avoid mixing these properties.

Why using padding instead of margin to create that space?

Using padding allows to paint elements’ background all across their parent container. Stretching from one edge to another. When this behavior is not seeked, for example when styling a heading with a bottom border that should be no wider than what appears to be the “content box”, authors can use a class (in the sheet already) to revert that styling (swaping padding values with margin values).

It creates horizontal white space too

  • Via margin – By default, vertical space is obtained through top margin. A top margin of 1.2em is applied to most block-level elements.
  • Via padding – Authors can uncomment two rules in the styles sheet to create spacing using padding instead of margin. The advantage of this method is that it prevents two common “issues”:
    • Collapsing margins - Margins will not collapse since elements are not styled with vertical (top/bottom) margins.
    • Loss of top margin when clearing floats – When an element clears a float, it “loses” its top margin, but that gap is preserved if top padding is used instead.

What else?

Rules in this base styles sheet are well commented and values that one would like to change (font-family, font-size, line-height, color, padding, etc.) are placed near the top of the file.

You can download base.css with comments or a minified version. My advice is to use these rules as a starting point to create your own styles sheet. Do not link to an external file to then override property values, instead, add, remove and edit anything you want to end up with a main styles sheet for your own project(s).

My base.css styles sheet is a work in progress. If you play with it, and if you see things that should not belong in there or to the contrary things that should be included, please join the discussion.

1 The YUI reset styles sheet sets a background-color on html. This styling makes the browser paint the background of body no taller than its content instead of matching the viewport’s height (this is by specs). I believe a future release of YUI reset will include this change.

Go to Source

3 Responses to Setting rather than Resetting Default Styling

Avatar

richarduie

March 21st, 2010 at 5:12 am

If you already know which browser supports it and which doesn't (it's easy – IE 6 does not support it), then you can use the standard methods for using different style sheets for different browsers. No JavaScript needed.

How to Use Different CSS Style Sheets For Different Browsers
http://www.thesitewizard.com/css/excludecss.shtml

Avatar

Judy

March 24th, 2010 at 6:26 am

Short answer…stay FAR away from these kind of scams.

Avatar

John C

May 20th, 2010 at 3:47 am

Don't pay attention to the answer before this one. This is an example of a Northern Renaissance painting, as opposed to an Italian Renaissance Painting. THere is a big difference. The Italian Renaissance began to emerge in Italy around the late 14th Century (1350-1375). North of the Alps, the Medieval Styles hung around a little longer and still continued to persist even into the period called the Northern Renaissance. In Italy, the Renaissance was marked by a renewed interest in classical antiquity. This makes sense considering it was in Italy where classical civilization reached its zenith. But north of the Alps, in modern-day Netherlands, this classical influence was limited, therefore the Renaissance style takes on a different look.

In this painting, the late Medieval style called Gothic is still apparent in the artist's obsessive depiction of minute detail. But the picture is called Renaissance because of the traces of humanism, the love and interest in all things human. Also, the perfected use of linear and aerial perspective are good indicators that we are dealing with a Renaissance painting and not a Medieval painting. This is an Oil painting. Medieval artists knew about oil paint, but never would have used it for a painting like this. Oil paint really came into its own during the Northern Renaissance period which started around 1450.

Comment Form

About this blog

This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.