Posts in the CSS Category

Reset Reasoning

Published 17 years, 7 months past

The reset styles are undergoing yet another overhaul, but in the meantime, I thought I’d answer a question several people have asked: why?!?  Why do this at all?

The basic reason is that all browsers have presentation defaults, but no browsers have the same defaults.  (Okay, no two browser families—most Gecko-based browsers do have the same defaults.)  For example, some browsers indent unordered and ordered lists with left margins, whereas others use left padding.  In past years, we tackled these inconsistencies on a case-by-case basis; for example, making sure to always set both left padding and left margin on lists.

But there are all kinds of inconsistencies, some more subtle than others.  Headings have slightly different top and bottom margins, indentation distances are different, and so on.  Even something as basic as the default line height varies from one browser to another—which can have profound effects on element heights, vertical alignments, and overall feel.

This is not something we consider very often.  We think of our CSS as modifying the default look of a document—but with a “reset” style sheet, we can make that default look more consistent across browsers, and thus spend less time fighting with browser defaults.  Rather than say “the size of that heading is just right”, forgetting that not all browsers size headings the same way, I have to write the CSS that sets the heading to be the size I want (or the design requires, which comes to the same thing).

This is why so many people zero out their padding and margins on everything by way of the universal selector.  That’s a good start, but it does unfortunately mean that all elements will have their padding and margin zeroed, including form elements like textareas and text inputs.  In some browsers, these styles will be ignored.  In others, there will be no apparent effect.  Still others might have the look of their inputs altered.  Unfortunately, there’s just no way to know, and it’s an area where things are likely to change quite a bit over the next few years.

So that’s why I don’t want to use the universal selector, but instead explicitly list out elements to be reset.  In this way, I don’t have to worry about munging form elements.  (I really should write about the weirdnesses inherent in form elements, but that’s for another day.)

There’s another reason I want to reset a whole lot of styles on a whole lot of elements.  Not only do I want to strip off the padding and margins, but I also want all elements to have a consistent font size, weight, style, and family.  Yes, I want to remove the boldfacing from headings and strong elements; I want to un-italicize em and cite elements.

I want all this because I don’t want to take style effects for granted.  This serves two purposes.  First, it makes me think just that little bit harder about the semantics of my document.  With the reset in place, I don’t pick strong because the design calls for boldfacing.  Instead, I pick the right element—whether it’s strong or em or b or h3 or whatever—and then style it as needed.

The maddening barrier to this is, yes, Internet Explorer.  See, in order to set all elements to have the same font weight and style (both normal) and have all elements use the same font face without breaking inheritance, I need to declare the following:

font-weight: inherit;
font-style:  inherit;
font-family: inherit;

But IE/Win doesn’t support inherit, which would seem to bring that whole effort to a screeching halt.  I can’t explicitly assign the values, like I did in a previous version of the style sheet, because that would block the effects of inheritance.  Say, for example, I wrote this instead:

font-weight: normal;
font-style:  normal;
font-family: serif;

Okay, now I have this rule later on in the CSS:

h1 {font: bold 2em Verdana, sans-serif;}

Then I have this markup:

<h1>Considering a <em>Truly</em> Annoying Omission</h1>

The em in the middle of the h1 will be un-boldfaced, and in a serif face.  With the inherit values, it would be bold and in Verdana (or some sans-serif font).  I should have realized that from the outset, but sometimes my enthusiasm gets ahead of my reason.

So do I drop those inherit declarations?  In the end, no.  They won’t work in IE/Win, but since I develop primarily in Firefox and Safari, that’s not actually a problem.  Their effects, as seen in my development environment, will still serve the purpose of reminding me to build up the styles I actually want, and not use the browsers’ defaults as a crutch.  There is the possibility of my forgetting that (for example) IE/Win italicizes em when I don’t want it to, but that’s something I’ll catch during the browser testing phase.

Hopefully this helps clarify my motivations and thinking.  I’ll follow up with a new (and hopefully final) version of the reset styles in another post, along with commentary on what other things I changed.


Reworked Reset

Published 17 years, 7 months past

Here’s the latest version of my “baseline” style sheet, with some changes based on feedback from readers on the original post.

/* Don't forget to set a foreground and background color 
   on the 'html' or 'body' element! */
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,
dd, dl, dt, li, ol, ul,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	font-weight: inherit;
	font-style: inherit;
	font-size: 100%;
	line-height: 1;
	font-family: inherit;
	text-align: left;
	vertical-align: baseline;
}
a img, :link img, :visited img {
	border: 0;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
ol, ul {
	list-style: none;
}
q:before, q:after,
blockquote:before, blockquote:after {
	content: "";
}

The changes are:

  1. The leading comment — rather than fill in some default document colors, which I hesitate to do given how often they’ll be changed, I just threw in a comment reminding the author that setting them is a good idea.  I’d expect that anyone who uses their own set of baseline styles will fill in their own favorite color set.

  2. font-weight: inherit; — this used to be normal, but it was pointed out that this would upset normal inheritance.  For example, if you set a div to be boldfaced, none of its descendant elements would inherit that boldness (because they’d be explicitly assigned normal).  Using inherit avoids this problem while still “zeroing out” boldface styling.

  3. font-style: inherit — same reasoning.

  4. vertical-align: baseline — this brings everything onto the baseline, including superscripts and subscripts.  This forces authors to determine the exact vertical offset they want for such elements, as well as any others they might care to vertically shift, as well as how they’ll accomplish said shift(s).

  5. a img, :link img, :visited img — this will make sure images in anchors and links don’t have a border by default.  Using a img covers images in named anchors, while the rest of the selector handles images inside either visited or unvisited links.  You might consider a img to be sufficient, and for now you’d be right.  But in the future, any element may be a link, not just a elements, so this gives us a bit of future-proofing.

I also put some spaces into the selectors to make them easier for me to read.  If you use these styles, you might consider stripping out the unnecessary whitespace to compact the rules as much as possible.

It was suggested that min-width: 0; be added to the first rule in order to invoke hasLayout, but Ingo Chao explained why that was a bad idea.  It was also suggested that text decorations should be removed from links, but I’d rather not.  I try never to mess with link decorations, and also figure that anyone who feels otherwise can add their own text-decoration declarations.

So we’ll see how well this one stands up to use in the wild.  Let me know!


Reset Styles

Published 17 years, 7 months past

At AEA Boston, I advocated using a “reset” or “baseline” set of styles, but not one based on the universal selector.  Instead, I said the styles should list all the actual elements to be reset and exactly how they should be reset.  During the Q&A afterward, an audience member asked me if I would create such a style sheet to share with the world, and I said that I would.

Then, during the break, someone else (sorry I’ve forgotten who!) reminded me that the Yahoo! UI group already did it with reset.css so I don’t have to.  Awesome!

…except that I don’t think it goes far enough in some areas, and a little too far in others.  So here’s my version of reset.css, based off of the YUI styles.

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,
dd,dl,dt,li,ol,ul,
fieldset,form,label,legend,
table,caption,tbody,tfoot,thead,tr,th,td {
	margin: 0;
	padding: 0;
	border: 0;
	font-weight: normal;
	font-style: normal;
	font-size: 100%;
	line-height: 1;
	font-family: inherit;
	text-align: left;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
ol,ul {
	list-style: none;
}
q:before,q:after,
blockquote:before,blockquote:after {
	content: "";
}

I omitted elements like hr and the various frame-related elements, as well as form elements like input and select, because of their general weirdness, though I may change my mind about those at a later date.  I intentionally left out dir and menu because of their deprecated status.

I’m absolutely open to questions, comments, and suggestions, so feel free to use the comments for that purpose.

(Side note: if anyone’s disturbed by the unitless value for line-height, please read my post “Unitless line-heights“.)

Addendum: There have been some good suggestions in the comments, so they’re definitely worth reading.  See also the followup post, which incorporates some of those suggestions.


Stylish Spam

Published 17 years, 7 months past

From my comment queue, possibly the first time I feel a spammer is really speaking to me as a person:

Did u ever heard about CSS…? it will help your site.

Do tell, oh random anonymous stranger whose site URL crudely references the genitalia of older females!  I wish to learn.


Events in CSS and Web Design History

Published 17 years, 9 months past
Here’s a fun Friday question for everyone: what do you consider to be some of the most important events in the history of CSS and web design?  How about some of the most overlooked events in that same history?  (And yes, an event can be both.)  I’m not looking for the “best” answers—I want to know what you regard as important, overlooked, or otherwise worthy of mention.  So tell!

I’d Like To Thank The Academy…

Published 17 years, 9 months past

Among all the other stuff this past week, I let something slip off the radar: an interview with me over at the Lunartics blog.  The interview was conducted via e-mail by Amy Armitage, who I briefly met last year at the Webmaster Jam Session in Dallas.  It’s not your usual “why is CSS important” kind of interview; Amy likes to keep things fun while still covering serious questions.  It’s definitely worth a read.

It also scoops news of a development I’ve never gotten around to mentioning: in October 2006, I was inducted as a member of the International Academy of Digital Arts and Sciences.  It’s a pretty incredible honor, given that it’s an invitation-only body of 500 members including “David Bowie, Virgin Group founder Richard Branson, Internet inventor and Google Chief Internet Evangelist Vinton Cerf, ‘Simpsons’ creator Matt Groening, Real Networks CEO Rob Glaser, and fashion designer Max Azria”.  The fact that my name appears on the same list as those people is jaw-dropping enough.  To me, it wasn’t the most stunning part by a long mile.

I’ll admit, though I’d heard of The Webbys, I assumed the IADAS was one of those name-collector groups, like those “Who’s Who in America” books where you pay to be listed.  Instead, I found that the IADAS levies no membership fees, and I was deeply surprised and pleased to discover that they invite people based on their actual qualifications.  How do I know?  Because my welcoming letter didn’t praise my web design work.  Instead, it cited my “dedication to promoting Web standards”, my “international recognition on the topics of HTML and CSS”, and proclaims that I’ve “helped inform excellence and efficiency on the Web”.

Yes, the text string “HTML and CSS” was actually in the letter.

It’s a little difficult to express how important this recognition is to me.  See, most of the time, I’m introduced and perceived as an influential web designer, which is frankly insulting to actual web designers everywhere.  If you aren’t reading this post via RSS, look around.  Does this look like influential web design?  Hell no.  At best, we can call meyerweb’s design minimalist and maybe—maybe—possessed of a certain elegance.  And it only took me five years and ripping off ideas from Khoi Vinh to get here!

But I’ve never claimed to be a designer.  I think the perception that I am one arises because I get linked to from people who really are designers.  I’ve always claimed to be a communicator.  I’m someone who’s done his best to explain, promote, and advance the technologies that let designers do their work.  I’ve invested tons of time and effort into making good web design easier without sacrificing clean and semantic markup.  I wouldn’t say that work is done by any stretch, but there’s been a lot of progress.  Sometimes I forget just how much.

And so, to be invited to join the IADAS not for what I’m usually thought to be, but actually for who I am—it’s an indescribable feeling.  A fantastically good one, certainly!  But not one I could describe no matter how many words I threw at the problem.

It’s a delicious irony, and I do so love my irony:  my powers of communication fail me when I wish to express my feelings over being honored for my communicating, over all those years, my love of the web and my passion for getting it right and the inner workings of how to make that happen.

But I can at least say this:

Thank you.  Thank you for coming to read my posts, for reading my books and articles, for listening to me speak.  Thank you for being the other end of the conversation.  Thank you for being open to what I have to say, and for responding with your insights and perspectives, all of which have changed me in untold ways.  Thank you for making everything I’ve done and said and written about the web worth far more than what I put into it.

Thank you for making this honor possible.


Two Books Together

Published 18 years, 1 week past

Last Thursday, I came down from the office to discover a stack of five boxes on the front porch.  Three were for Kat, who is one of those annoying people who plans way ahead for Christmas, and two others were my author copies of CSS Web Site Design (formerly “CSS Hands-On Training”).  This is a title I did for lynda.com, and published by Peachpit, and it’s most tersely described as “Eric Meyer on CSS, but for beginners”.  It’s also the hard-copy version of the video training title “CSS Site Design“, and includes all the videos and exercise files from the video title on a CD-ROM bundled with the book.

After I’d hauled all that into the front hallway, I grabbed my car keys and headed out the back door to run my errand.  At which point I nearly fell over two more boxes, these containing my author copies of the third edition of CSS: The Definitive Guide from O’Reilly.  This is of course an update of the second edition, which contains some updates based on the latest version of CSS 2.1, expanded selector coverage, updated compatibility notes taking IE7’s improvements into account, and corrected errata from the previous edition.  It’s not a major update compared to the second edition, admittedly, but if you don’t already own the second edition, it’s well worth acquiring (if I do say so myself).

It’s a bit funny that both sets of books arrived on my doorstep the exact same day, considering that the two projects started out well separated, and gradually synched up.  At first I was going to write one and then the other, but various complications set in and they started to interweave.  I finished their final reviews with a whole lot of overlap—that was a fun couple of weeks—and now, the waves have fully amplified.

What really cracked me up was that the next day, I got packages from both Peachpit and O’Reilly, each containing a single copy of the respective books, and each containing a note along the lines of “Here’s your advance copy; the rest should arrive in a few weeks!”.


Hands Across the Sea

Published 18 years, 3 weeks past

Cripes.  In preparing to mention some upcoming appearances, I realized I’d never gotten around to mentioning a couple of events in the recent past; specifically, AEA Seattle and the Webmaster Jam Session.  I’ll get to those in the next couple of posts, and then fire off a couple of reviews.

What I called you all here for, though, was to pass along news of an upcoming two-continent microtour.  Yes!  You can almost feel the white-hot spirit energy of this global adventure, can’t you?  I know I can, and unless I’m very much mistaken, I see it in your eyes too.

It’s a special thing we’ve just shared.  Don’t tell anyone else.

The festivities will start with my return to London (UK, not Ohio) for a two-day Carson Workshop on December 7th and 8th.  You can learn more at the Carson Workshops site, of course.  I hear tell that a goodly chunk of the limited seating has already been claimed.  In the course of the two days, I’ll be leading an expedition into the very heart of CSS.  From the darkest, thorniest jungles to the spectacular hidden vistas glimpsed only by a few lucky souls we will travel, and those who emerge alive will truly be a band of brothers and sisters.

Since I’ll already be in London on the date, might there be a stop by the BBC Backstage Bash?  Could be.  Could very well be.

From the sun-kissed shores of wild England, I’ll wing my way to verdant Boston for Web Design World.  It will be there that I will spend half a day—said day being December 11th—presenting a condensed version of some parts of the content covered in London, an overland flight giving us an idea of where the previous week’s group blazed a mighty trail.  Yes, I’d like to present it all, but since I have not (yet) fully asserted dominance over the flow of time, I have no way to fit two days into half a day.  It would be like trying to fit a Danish prince inside a nutshell.  No matter how you or he may espouse theories of some fabled infinite space to be ruled within that diminuitive husk, homey just won’t fit.

My work in Boston having been completed, I will make my way homeward at last, nearly a full week and many thounsands of miles after leaving it, tired but triumphant, ready to face the New Year and all the changes it will bring.

So now you know.  And as well we know, knowing is half the battle.

(For those who might be in the know, a bonus prize to anyone who can identify the web site and author I was homage-ing in this post.  Not parodying!  No no!  I’m not sure such a thing would be possible in any event.)


Browse the Archive

Earlier Entries

Later Entries