Welcome to CSS Wizardry—Web standards design and development

Welcome to the all new CSS Wizardry. I am Harry Roberts—a 19 year old web developer living and working in Leeds. ‘Work’ is the exciting new startup Venturelab where I work on a range of projects, dealing with design and development with particular focus on accessibility, semantics, usability, clean xHTML, sensible CSS, grids and typography.


Zebra-striping rows and columns 8

Zebra-striping tables is certainly not a new thing; it has been done and discussed for years. They (allegedly) aid usability in reading tabular data by offering the user a coloured means of separating and differentiating rows from one another. I say allegedly, there has been research into their effectiveness, conducted by Jessica Enders over at A List Apart which proved pretty inconclusive.

Striping a table’s alternate rows couldn’t be simpler. By programatically adding a class of odd or suchlike to every other <tr> you can then apply styles to this row (usually a pale background colour) and create zebra-stripes. An even better method would be to ditch the extraneous class and use the nth-of-type selector, thus:

tbody tr:nth-of-type(odd){
  background:rgba(255,255,136,0.5); /* Pale yellow with 50% opacity */
}

What the nth-of-type selector is doing here is looking for every odd <tr> in the <tbody>, that is to say the 1st, 3rd, 5th, 7th and so on.

By understanding this, we can apply that logic to create zebra-striped columns, too. Thus:

tbody td:nth-of-type(odd),
thead th:nth-of-type(odd){
  background:rgba(255,255,136,0.5);
}

Above: Here we target every other <th> in the <head>, and <td> in the <tbody>.

We can also combine the two, to create a table where every other row and every other column is striped simultaneously, and by using the rgba() colour declaration we can effectively layer the stripes, therefore showing where they cross over. The code for this simply combines the two:

tbody td:nth-of-type(odd),
tbody tr:nth-of-type(odd),
thead th:nth-of-type(odd){
  background:rgba(255,255,136,0.5);
}

You wanna see a demo?

Sure thing, here you go…

Addendum

After questions about browser support, I have decided to add a little onto the article…

The selectors involved here are only supported in CSS3 capable browser, that is to say pretty much anything but Internet Explorer. However, due to zebra-striping’s negligible benefits and inherently progressive nature, I don’t feel that it is a feature that is important enough to warrant full cross-browser support. Research shows that tables are just as usable without zebra-striping as with, therefore in IE et al, the user is not receiving a sub-par experience.

Of course if you do want to support Internet Explorer, you can always revert to programmatically adding an odd class to <tr>, <th> and <td> elements.


Semantics and sensibility 7

For a while now, sensible naming conventions and semantics have been confused. Things such as class="left" or class="clear" have been deemed insemantic, whereas in reality, semantics really doesn’t stretch that far… Let me illustrate with some code examples:

Insemantic code

The following code is just plain wrong, it’s insemantic, using the wrong elements for the wrong job:

<div class="nav-link"><a href="/">Home</a></div>
<div class="nav-link"><a href="/about/">About</a></div>
<div class="page-title">About</div>
<div>This is some page text about some stuff...</div>

Insensible code

This code is perfectly semantic, it just uses some silly classes:

<div class="border">
  <h2 class="red">This is a heading</h2>
</div>

Semantics concerns itself with elements…

…and not the names assigned to them. Using the correct element for the correct job is as far as semantics goes. Standards concerning naming of those elements is all about sensibility.

Semantics sets a standard from which it is very difficult to stray. Headings are marked up with a <h1–6>, a list with <ul/ol/dl> and so on. You cannot, however, define a convention for naming the IDs and classes of these. <div id="contact">, <div id="kontact"> and <div id="contact-info"> all bear different names, but are all equally as semantic. All three are examples of semantic and sensible code.

However, take the following examples: <div id="bottom">, <div id="lower-area"> and <div id="b">. These examples exhibit semantic code, but with insensible namings.

Be sensible, for our sake

Semantics should be adhered no matter what—web standards are good. Naming however is totally down to you, you can call your elements whatever you wish. <div id="a">, <div id="b"> and <div id="c"> are all possible, but not sensible.

“Always code like you’re working in a team, even when you’re not.”

I have actually seen markup like this, and the developer’s reasoning was ‘I like to keep my markup as lean as possible, and I know what a, b and c do’.

While this is all correct, and passable, it’s not really very sensible. He might know what a, b and c do, but what about the person who inherits the project? For all his justification of code bloat was somewhat advanced (really decreasing markup size), the impression the next guy to see his code will have will be ‘WTF was this guy thinking?!’ Always code like you’re working in a team, even when you’re not.

Final word

“An ID/class should be as short as possible but as long as necessary.—Jens Meiert

Semantics and sensibility are not the same. Anyone who tells you that class="left" is insemantic is wrong. Be semantic and be sensible. Pick names which are descriptive. An ID/class should be as short as possible but as long as necessary.


Thoughts on Dribbble 11

For a while I was really gutted I didn’t have a Dribbble invite, I posted a tweet requesting one, and Drew McLellan gave me one. From the off I was kind of disappointed with it. It’s just Twitter with screenshots. Anyway, I wrote these thoughts down the other day elsewhere, and I thought I’d do a mini-post to share them more publicly. They are totally unrehearsed, unedited and completely off the cuff:

“I think it’s just another place where the more famous designers just pat each other on the back, regardless of what they actually produce.
It’s too elitist and the more known designers only follow each other, leaving less known people following them but their own work barely been seen. This in turn fuels the cycle—the famous get more so, while the more humble designers go unnoticed. I am seriously unimpressed with Dribbble”

So, if you’re really really wanting a Dribbble invite, don’t worry; you’re not missing much.


On a more personal note… 2

Lately, I’ll admit, I’ve not been too hot on replying to emails and suchlike. If you have emailed me recently I do apologise, however I’ve not turned my home PC on in almost two weeks now, and it feels great. I spend eight hours a day in front of my computer at work, and usually the first thing I do when I get home is turn the computer on there. I could sometimes spend over half of my day sat at a PC.

While I have written several resources in my spare time, and thoroughly enjoyed each, they are very time consuming. The exposure and nice comments they bring are great, but sometimes it’s hard to keep on putting in hours and hours of work in exchange for a pat on the back—that’s why so few people actually take the time to do it.

A photo of me riding trials, taken by Suzanna Haworth

Photo by @suzehaworth

So, having gotten back into trials lately, combined with improving weather, I’m devoting more spare time to that at the moment. Evenings not spent with Suze will most likely be spent riding. Not at my PC.

This is not to say I won’t be writing articles any more, far from it. I love writing articles, and as CSS Wizardry’s exposure has rocketed recently (thanks to people like yourself) writing articles is even more rewarding than ever, and the quality of the comments and feedback is increasing too. I have article ideas all the time, and will post whenever I have the chance. All that’s happening at the moment is I’m stepping back from the PC for a bit, for my health and sanity more than anything. Too much time at the PC can’t be doing me much good. A result of which is that I haven’t been on email for a couple of weeks now…

If you have emailed and it is urgent, I apologise. Please tweet at me as I’m always on Twitter. I’ve also had emails regarding permission to translate Web Design+—if you’d like to translate it that’d be great, you have my permission to do so (provided you don’t pass it off as your own, of course).

Also, regarding freelance work; I shan’t be undertaking any form of freelance for the foreseeable future, sorry…

Keep following me on Twitter though, as I’ll still be posting links and things as ever, and add the CSS Wizardry RSS feed so any articles I do write, you’ll hear about first.

I’m not going, just relaxing. And I think you should too. Move away from your computer, get outside and have fun!

Cheers,
Harry


Building sites without using IDs or classes 33

This morning, for one reason or another, I decided to have a go at coding up a page without using any IDs or classes in my markup, and therefore none in my CSS. I’m not sure why I tried it, I guess I just did… In order to make it a fairly painless job I dove straight into the browser and coded up a simple header, footer, two column layout. View the demo and be sure to view the source.

Continue reading this post →


Search CSS Wizardry

Archives

Categories

Twitter—2169 followers

You should follow me.

Subscribe—RSS