Apr 2, 2009

Posted by Nicole in Web Development | 41 Comments

Create The Perfect CSS Reset

Create The Perfect CSS Reset

As every new and experience web developer knows, different browsers process code differently. What may look perfect in Firefox, may be off in Internet Explorer. As annoying and tedious it is to make your website browser compatible, one CSS style sheet can save you a bunch of time from fixing IE6 errors.

These are called CSS Reset sheets and can reduce the time you spend on browser compatibility by resetting CSS elements.

There are many CSS Resets all over the internet that help combat browser problems. Below are a few great CSS Resets:

tripoli-css-reset

css-cheatsheets_image0201

eric-meyer

Instead of focusing on the CSS Reset Frameworks, I want you as the readers to help me in the process of creating a perfect CSS Reset style sheet.

The basic reset

I use Eric Meyer’s Resetting Again as my CSS reset sheet and with his knowledge, his style sheet serves as a start to browser resetting and compatibility. Here we will start with his Resetting Again style sheet:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

Blockquotes are important

His style sheet covers the basics of  resetting the browser’s styles, but if you look at the comments on Eric Meyer’s Resetting Again, you will see people are discussing more ways to reset the browsers. If you look at the comment by Paul Chaplin, he commented on the removal of from Reset Reloaded:

blockquote:before, blockquote:after, q:before, q:after
{
content: "";
}

He brought up that Safari will “automatically generate doubled quotes when there are hard-coded quotes in the markup” if not specified properly. On his blog, he has properly coded a fix to the blockquote code:

blockquote, q
{
	quotes: none;
}

/*
Safari doesn't support the quotes attribute, so we do this instead.
*/
blockquote:before, blockquote:after, q:before, q:after
{
	/*
	CSS 2; used to remove quotes in case "none" fails below.
	*/
	content: "";
	/*
	CSS 2.1; will remove quotes if supported, and override the above.
	User-agents that don't understand "none" should ignore it, and
	keep the above value. This is here for future compatibility,
	though I'm not 100% convinced that it's a good idea...
	*/
	content: none;
}

Adding this into Eric Meyer’s reset sheet includes an amazing blockquote reset for Safari, which is becoming a very popular browser. So now our style sheet should look like this:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

blockquote, q
{
	quotes: none;
}

/*
Safari doesn't support the quotes attribute, so we do this instead.
*/
blockquote:before, blockquote:after, q:before, q:after
{
	/*
	CSS 2; used to remove quotes in case "none" fails below.
	*/
	content: "";
	/*
	CSS 2.1; will remove quotes if supported, and override the above.
	User-agents that don't understand "none" should ignore it, and
	keep the above value. This is here for future compatibility,
	though I'm not 100% convinced that it's a good idea...
	*/
	content: none;
}

Combat the IE font sizing bug

If you look further down the page, you will see a comment by Pari that brings up the IE Font Sizing Bug and how the font should be changed to font-size: 100.01% to counter the font sizing bug. Virtually, there is no change between 100% and 100.01%, but to reset fonts, we will add that to our style sheet:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100.01%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

blockquote, q
{
	quotes: none;
}

/*
Safari doesn't support the quotes attribute, so we do this instead.
*/
blockquote:before, blockquote:after, q:before, q:after
{
	/*
	CSS 2; used to remove quotes in case "none" fails below.
	*/
	content: "";
	/*
	CSS 2.1; will remove quotes if supported, and override the above.
	User-agents that don't understand "none" should ignore it, and
	keep the above value. This is here for future compatibility,
	though I'm not 100% convinced that it's a good idea...
	*/
	content: none;
}

End result

Lastly, optional, but two essential techniques to reset forms are adding textarea { overflow: auto; } which automatically disables the scrollbar IE places inside textareas and putting input { border: 0px solid white; margin: 0;  padding: 0; } into our style sheet to reset the input and take away the borders that different browsers put. You may take out the last one if you want to keep a simple input for a simple contact form, but if you are planning to style the inputs together or individually; you should put that into the style sheet. Nonetheless, our style sheet ends up looking like this:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100.01%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}

blockquote, q
{
	quotes: none;
}

/*
Safari doesn't support the quotes attribute, so we do this instead.
*/
blockquote:before, blockquote:after, q:before, q:after
{
	/*
	CSS 2; used to remove quotes in case "none" fails below.
	*/
	content: "";
	/*
	CSS 2.1; will remove quotes if supported, and override the above.
	User-agents that don't understand "none" should ignore it, and
	keep the above value. This is here for future compatibility,
	though I'm not 100% convinced that it's a good idea...
	*/
	content: none;
}

textarea { overflow: auto; }
input { border: 0px solid white; margin: 0;  padding: 0; }

Now, it’s your turn as the reader to discuss this with me and continue the improvement of this reset sheet. Please comment in this post your contribution to this style sheet. Point out the flaws: mine’s, Eric’s and the commentor’s flaws.

  • Share/Bookmark
  1. I think you have reached a very well result. Can’t think of a recommendation. Thanks for sharing

  2. to the global reset by eric meyer i usually add a baseline grid which sets the height of block elements to multiples of the body line-height, so i set font-sizes and top/bottom margins for the html elements there.

    i also have a typography stylesheet where i set styles for stuff like ins or del (font-style, font-variant, font-weight, text-decoration, border-bottom-styles)

    in addition to that i have a different stylesheet for color and background (-images), so i wouldn’t set any color in the global reset, as you did with input { border: 0px solid white }

    textarea { overflow: auto; } is a nice addition, i will use that and also the safari fix is nice to have.

    in my opinion setting margins and paddings to 0 is enough for a global reset, all the rest has to be handled in extra stylesheets.

    thanks for your first post, it evoked thinking.

    btw, the submit comment button text beneath the comment form is cut of on ff3/winxp.

  3. Great site this serenedestiny.com and I am really pleased to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

  4. This is very up-to-date info. I’ll share it on Digg.

  5. this is a great story. Doing something very similar at this very moment. Added your site to my RSS reader.

  6. that is really cool, i don’t think i’ve heard of that before, resetting css sheets could be really cool if you are working on a lot of different versions.

  7. If you have to do it, you might as well do it right

  8. I rarely comment on blogs but yours I had to stop and say Great Blog!!

  9. Not that I’m impressed a lot, but this is a lot more than I expected when I stumpled upon a link on SU telling that the info here is awesome. Thanks.

  10. Man, that’s great…Thanks for providing such a good info………

  11. Wonderfull…

  12. Incredible site!

  13. Great work, well researched

  14. Hi there, not sure that this is true, but thanks

  15. It is the coolest site,keep so!

  16. I rarely comment on blogs but yours I had to stop and say Great Blog!!

  17. That was nice. Thank you for sharing this one.

  18. I want to say – thank you for this!

  19. I can find many things that I look for here! Thank you very much!

  20. Thanks for the review! I want to say – thank you for this!

  21. I’d just like to thank you for taking the time to create this internet website. It has been extremely helpful

  22. You have a great website. Keep up the good work.

  23. win now says:

    I think that your site is very interesting and nice. Good job !

  24. Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  25. hey this is a very interesting article!

  26. I really like the layout and colors that you chose for this website! It certainly is incredible! :)

  27. Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  28. nice site keep it on ;)

  29. I’m happy I found this, it just made my day!

  30. This site is truly a great resource thanks for all your hard work

  31. Are you from San Diego?

  32. thanks for the catch. I’ll get in there and fix it….
    serenedestiny.com – cool!!!!

  33. Are you from San Diego?

  34. You have a great website. Keep up the good work.

  35. Hi! very amused by the website .

  36. hold m poker texas says:

    Your site looks great! Best of luck to you.

  37. I like your website I will share this with friends

  38. Мне очень понравился текст, так как и у самого трудности с определениями ) Но вот читать трудновато – не отформатировано.
    serenedestiny.com – супер!!!!

  39. Thank you. You have helped someone more than you could know.

  40. Very informative and detail…thanks

Trackbacks/Pingbacks

  1. links for 2009-04-07 « pabloidz - [...] Open Thread: Create the perfect CSS reset (tags: css) [...]
  2. 網站製作學習誌 » [Web] 連結分享 - [...] Create the perfect CSS reset [...]
  3. Create the perfect CSS reset | vitali software - [...] Source: Open Thread: Create the perfect CSS reset « Serene Destiny. [...]
  4. Creating the Perfect CSS Reset - [...] DIRECT LINK » [...]
  5. Creating the Perfect CSS Reset | Misr IT Reader - [...] DIRECT LIN&#75&#32» This entry was written by admin and posted on May 25, 2009 at 3:55 am ...
  6. 今週の管理人Bookmark (5/24-5/31) - ElectronicBrain is eating BreakFast - [...] Open Thread: Create the perfect CSS reset | Serene Destiny [...]

Leave a Reply