Categories
Web Design

How to Give Useful Advice

The internet is a fantastic resource for the budding web developer. With plenty of blogs dedicated to improving the web, new tips and best practices are spread easily and often. But is this advice always useful? The veteran web developers of the world have a responsibility to their community to provide advice that is not only correct, but also well thought-out and properly explained. And sometimes, even the pros miss the mark.

Last week, I stumbled across a post from Six Revisions entitled 10 Random CSS Tricks You Might Want to Know About. Thinking that one can never know too many CSS tricks, I figured I’d give it a read and hopefully come away with something I didn’t know before. Instead I came upon a mess of poorly-chosen and poorly-explained advice that some hapless beginner may now completely misuse! Needless to say I was startled.

At first, I thought about leaving a comment denoting my dissatisfaction with the quality of the post, but I soon decided that that wouldn’t have been particularly productive. Better to point out not only the flaws, but also what is done well and maybe add a few improvements, right? So that’s what I did. Open the original article for reference, and follow along with my notes!

1: Set body font-size to 62.5% for Easier em Conversion

This is a neat math hack, but poor advice for the novice web developer. The whole point of using em is that it is a relative unit of measure. Suggesting that you set your body font in such a way that it will be easier to convert em to px implies that you’re not using em as a relative unit at all — you’re just using it in place of px. At that point you’re better off just using px and saving yourself the overhead of converting it at all.

A better tip would be to explain how em really works and to demonstrate how powerful relative measure really is. A timely example would be for a mobile-optimized design: With so many devices out there covering a wide variety of screen resolutions, proper use of em can help ensure that everyone gets a properly-scaled view.

2: Remove Outline for Webkit Browsers

This could alternately have been called “Break Accessibility for Webkit Browsers”. It’s a horrible tip, especially for an impressionable designer just getting into web development. Forms are focused for a reason — so that the user can see where she is in the page. When this is removed, it weakens keyboard accessibility and annoys power-users that navigate through forms sans mouse. There is no good reason to do this. Ever.

A much better tip would be to promote proper use of the CSS :focus pseudoclass. Instead of removing the border, change it to something that better matches your design. Or change the background color or some other property so that it’s still clear when a form element is highlighted. Whatever you do, make sure you aren’t breaking an important accessibility feature.

3: Use CSS transform for Interesting Hover Effects

This is a good tip; there are plenty of interesting new effects coming out in CSS 3, and anyone that has worked on a website with me can tell you that I’m a huge fan of rollovers. What irks me about it is the example they chose — using the scale function to resize text. This is ridiculous for two reasons:

  1. You don’t need scale() to do this, you could just as easily change the font-size property.
  2. Artifically scaling a font makes it look uglier. You won’t get this side-effect using font-size.

The article should have either found another way to show the benefits of the scale() function (images are a classic) or chosen an effect that suits text rollovers better, such as text shadow.

4: Target IE6 and IE7 Browsers without Conditional Comments

This is my least favourite “trick” in the entire list. The whole reason we have conditional comments is because before they came along it was a pain in the ass to target browsers like IE6 and IE7. Why anyone would condone reverting to exploiting browser bugs via CSS to target specific browsers is beyond me. Conditional comments are much, much better suited for the job.

Predictably, my preference for this tip would be to explain why conditional comments are better than awful, outdated hacks. The main advantage is that they allow you to localise your browser targeting to one spot in your mark-up, rather than all over your CSS file. This makes it much easier to maintain and has the added bonus of avoiding ugly character-based hacks all over your otherwise-gorgeous styles.

5: Support Transparency/Opacity in All Major Browsers

This one is largely okay. It’s a good tip, and the example is solid, I just found the introduction a bit lacking. A possible improvement would be to mention that originally, every browser had their own transparency hack and it wasn’t until CSS 3 that opacity was officially added to the specification. This way the novice developer following along gets a touch of back-story regarding why Internet Explorer is different from its counterparts.

6: Use !important to Override Normal CSS Precedence Rules

This is a good tip (I’m willing to bet a lot of people don’t know about !important), but it only explains half the problem. What isn’t covered is when to use !important, and that’s just as, well, important. The example given is too simplistic to be useful.

The ideal tip would describe a case where using !important is necessary. Like those times when you’re dealing with some poorly-auto-generated HTML, and you need to override some inline styles.

7: Centering a Fixed-Sized Element

This example is poorly explained. It reads a lot like “do this magic CSS, and *poof* your content will be centered!”. That’s not how CSS works, nor is it a good way to learn. Why not explain how the styles work? They’re not obivous. Furthermore, why not provide a few alternatives? If the dimensions of the container are known, for example, the math gets quite a bit easier — and that will be a very common case.

This tip would be more useful if the inner workings of the sample CSS were clearly explained. Educating a reader is always better than conjuring up a magic block of code with no elaboration.

8: Easy Web Fonts with Google Font API

This is one of two tips that is already really useful. There are no glaring errors, the example is current, and the content is still likely unknown to a large number of developers. There’s even a bit of history regarding the current state of @font-face! I wouldn’t change a thing.

9: Prevent Line-Wrapping of Text Elements

This tip again fails to mention when it should be used. “Sometimes” is too vague, and even the example of link text isn’t really justified (are there advantages to no-wrapping link text? what are they? when else is this useful? etc). By answering a few more questions, this could be considerably more useful advice.

10: Vertically Align Text

This is the second already-useful tip. It explains the problem, introduces the solution, and explains some of the solution’s shortcomings. Exactly the kind of information necessary to really understand this tip.

§

There we have it; a few tweaks and these potentially-harmful tricks can flip into advice that is decidedly useful. We can draw a few conclusions from our observations above:

  1. Start with the problem. Clarifying the problem up front shows that your advice is practical.
  2. Be specific. Removing ambiguity makes advice easier to use.
  3. Explain yourself. Justifying your reasoning helps your subjects learn.
  4. Provide compelling examples. Make sure you hit both what and when.

So the next time you’re offering some advice, don’t just stop there — offer some advice that is really, truly useful. Your community will thank you.

Categories
Web Technology

Why I don’t hate Internet Explorer 8 (not that I’d ever use it)

This week’s entry is a double feature about Internet Explorer. Part 1 examined why IE4 was awesome. Read on for part 2, where I’ll admit that I’m grateful for IE8.

Let me start by saying that in general, I find Internet Explorer appalling. The fact that so many people have been supporting an insecure, slow, feature-weak, standards-deviant browser with serious rendering problems and an awful user interface for so many years afflicts my soul with such utter disdain for Microsoft’s line of browsers that I automatically regard every new incantation thereof as an affront to both the web and mankind as a species.

Now that that’s out of my system, I don’t entirely hate Internet Explorer 8. I wouldn’t use it, not with so many better alternatives just waiting to be explored*, but it does offer one massive improvement over its predecessors that I’m very pleased with: IE8 has fantastic CSS 2.1 support.

I’m not making this up.

Check out the standards support table on this page, specifically the secion about CSS 2.1. Look at the massive difference between IE6/IE7 and IE8. Even Firefox 3 and Opera 10 can’t claim the same level of compliance. IE8 isn’t just a competitor when it comes to supporting CSS 2.1, it’s a role model.

This is a big deal.

For the first time ever, web developers can finally count on using standardized CSS to create a modern web experience without having to worry about “how to handle Internet Explorer”. Granted there is still the matter of older versions of IE, but with Windows 7 repairing a lot of the damage done by Vista, more and more users are upgrading to a new OS, and with that, a new browser. Writing cross-browser CSS is becoming easier than ever before.

Of course, many people will argue that simply supporting CSS 2.1 isn’t good enough (and they’re right). Internet Explorer is still way behind its competitors when it comes to newer standards such as HTML 5 and CSS 3. But what if this is just the beginning? Internet Explorer 9 is already well into development, and if Microsoft can turn the hobbled CSS implementations found in IE6 and IE7 into what is now in IE8, who’s to say they won’t be able to step up support for CSS 3 and/or HTML 5 in IE9? In as little as a year or two from now, Internet Explorer may be a legitimate browser for cutting-edge web experiences.

Share some thoughts!

What do you think of IE8? What about Internet Explorer in general?


* For the curious, the browsers linked in that phrase are the ones that were selected to show up in Windows 7’s “browser ballot” in Europe due to antitrust charges brought by the EU against Microsoft’s bundling of Internet Explorer with Windows. Computer World offers a great summary and FAQ on the matter.

Categories
Web Design

What is a Font Stack?

Font Stack (n) : A list of several fonts provided from a website to a browser via CSS from which the browser will chose a font with which to render the associated text. eg. font-family: Helvetica, Arial, sans-serif;

This is a pretty simple concept to understand. To show text on screen, the browser needs to use a font, and the way web developers tell the browser which font to use is by making a font stack like the one shown above. The browser will go through the list from left to right, and when it finds a font that it can use, it renders the text using that font. So you put the ideal font first, then the next-best-thing that looks pretty similar, then maybe another back-up or two, then a default like serif or sans serif, which essentially tells the browser to use whatever default font it has of that type.

I was sifting through WordPress themes the other day when I stumbled upon:

font-family: Georgia, sans-serif, Verdana;

Let’s take a moment to go over the various atrocities committed by this abomination:

  1. Georgia is a serif font, while Verdana (and obviously sans-serif) are sans-serif fonts. It’s purely nonsensical to include serif and sans-serif fonts in the same stack — you either want serifs or you don’t.
  2. Browsers choose fonts from left to right, remember? And sans-serif is one of those default fonts we talked about, so it’s guaranteed to always be supported by all browsers. This means that the Verdana in that stack will never be used, ever. There is absolutely no reason to include another font after a default.
  3. One of the notable characteristics of Verdana is that it’s very wide. The wider the font, the less characters will appear on a single line. It’s a terrible idea to include a wide font, such as Verdana, in the same stack as a comparatively thin font, such as Georgia (or Arial, which is a more common mistake) because now the width of your lines, the length of your page, and the general look and feel of your text vary greatly depending on which font is used.

Horrible! But all is not lost; here are a few simple guidelines to make sure you don’t create anything similar:

  1. Never mix serif and sans-serif fonts in the same stack.
  2. Always include a default font, but always put it at the very end.
  3. Always test each font first to make sure your lines break in about the same places and that your text still has the same general shape.
  4. Never guess — the internet is a wonderful place with plenty of resources for the aspiring typophile, use them!