在自己所做過的項目中還沒有使用過頗為流傳的 CSS Reset,就發現了下面這篇文章。
其實有時候不需要去技術跟風,只需瞭解一下便可。那些東西有一定的道理,但不一定適合。就像 CSS Sprite,用的有感覺了,就知道什麼地方該用,什麼地方不該用。如果每處都用,那就成了濫用了。
個人在平常項目中用到的最多的也就是下面這個
* {
margin: 0px;
padding: 0px;
}
覺得沒有必要用 CSS Reset,個人感覺有點畫蛇添足了。
IE 6 沒特殊要求,基本上是放棄了。因此幾個像素的大小並無太大影響,使用者畢竟不可能開著2個以上瀏覽器同時查看一個頁面吧。只要看上去精緻,該對齊的能對齊了就 OK 了。
When asked recently about using a CSS reset stylesheet, I readily
admitted that I don't use them. I don't use them for my blog or for any
project that I work on. Admitting such can raise an eyebrow or two.
Reset stylesheets are definitely becoming commonplace — as you'd expect
with companies like Yahoo
and industry leaders like Eric Meyer
actively using them.
So, why haven't I jumped on board?
What is a CSS Reset?
In case you've never heard of such a thing, a CSS Reset is designed
to set a number of element styles to a specific baseline that creates
consistency across various browsers.
In the beginning
When the idea of a reset style was first introduced, it was very
basic. It reset the margin and padding for all elements. The problem
with that was it caused havoc with elements that didn't want their
margins or padding reset (namely, form elements).
* { margin:0; padding:0; }
From there, people worked on adding to and fine-tuning the reset stylesheet to be more flexible and to reset more styles. The Meyer reset
is probably the finest culmination of this effort.
Eric Meyer's Reset
Eric Meyer's reset took the concept of resetting margin and padding
and took it to a whole new level, stripping styles from a number of
elements, forcing you to think about what you wanted and add them back
in. List items would no longer have bullets, headings would no longer be
bolded, and most elements would be stripped of their margin and
padding, along with some other changes.
Working with Nothing
The problem I've had with these resets is that I then find myself
declaring much more than I ever needed to just to get browsers back to
rendering things the way I want. As it turns out, I'm perfectly happy
with how a number of elements render by default. I like lists to have
bullets and strong elements to have bolded text.
And I'm okay if the various browsers show things slightly differently.
I'm okay if one browser displays an H1 a few pixels larger or smaller
than other browsers. If one browser defaults to circle bullets and
another to squares, that's usually not a problem. If it is, then I
create a style that addresses that specific issue. I don't reset it back
to zero and then set it again to what I really want.
One of the principles I took away from the Web Standards community
was the concept that pixel perfect precision across the various
rendering engines was impractical and a remnant of the table-based
layouts of yesteryear. With CSS and progressive enhancement, it was okay
that things might look a little different from one browser to the next
because of variations in what they supported.
Building up
With that said, the idea of developing a base CSS file that defines
some common styles that I often want from project to project — like
turning off margin and padding for form elements — is a good idea.
We're seeing various CSS frameworks crop up such as Blueprint
, YUI
and 960.gs
.
Each breaking the system down only to build it back up again. Each
starts with a reset, then adds on typography and a grid system.
Each of those still seem like more than I need, even though none are
that large in size. Blueprint is the heaviest at around 13KB
uncompressed but also includes lots of extras like styles for error
messages and a print stylesheet.
Less is more
One of these days I'll put together my own base CSS or maybe I won't.
To date, I haven't felt myself being overly repetitive in the styles
that I set; and I haven't thought to myself, "oh, the hours I'd save
myself if only I had a reset stylesheet."
So, while I have nothing against CSS reset stylesheets, I simply don't use them personally and I think that's okay.
Published April 17, 2008 Categorized as HTML and CSSShort URL: http://snook.ca/s/889