CSSKarma

display your <style>

designing the web since 2002

Archive for November, 2008

|

Header and Footer in the Semantic Web

Thursday, November 20th, 2008

atricle banner

A couple years ago I read through Andy Clarke’s Transcending CSS and it really made me think about semantic naming conventions I had otherwise taken for granted. By now, most of us (at least people reading this blog) practice using semantic markup and meaningful class & ID names. But can we do it better? Probably. There’s always room for improvement.

Andy’s book was (still is) filled with many techniques that I hadn’t seen before. I had fallen into the trap that many designer/developers fall into. I was doing things just because I had seen other others doing it and assumed it was the best way. This is why most people still use <div id="wrap"> even though it’s usually unnecessary.

I’m mainly talking about semantic div naming. Specifically "header" & “footer”. I’ve had a while to think through this, so bear with me here.

Basic semantics

The basis of the semantic web is to look at content first, and then decide which element to use, based on that content. Using a list for navigation rather than a paragraph with line breaks (for a brutal example), using an h2 instead of regular bold text, things like that.

Semantic elements extend beyond just XHTML, it extends into your class and ID names. We’ve all seen articles telling us to use names like "error", rather than "red" and "highlight" rather than "yellow". These names are more meaningful and leave room in the future changing the CSS behind them, while still keeping them meaningful.

The same principle should be applied to ID naming, but for some reason, it hasn’t fully taken off. We’re using names like "header", "footer", and "sidebar" in our every day development. On the surface they’re fine, but in the long run they can really hinder future design changes.

What information can be gathered from these div names?

Header

From the name alone, you can tell that this element is at the top of the page. From experience we can assume it also contains some kind of information about the site (name, logo, tagline, etc.). But it’s definitely at the top of the page.

Footer

Footer tells us this is located at the bottom of the page.

Sidebar

The name "sidebar" contains no information about what it contains, just that it runs along, either the right or left side of the page.

The popular way
<div id="header"></div>
<div id="nav"></div>
<div id="main"></div>
<div id="sidebar"></div>
<div id="footer"></div>

What if you want to put the logo somewhere else? Maybe your copyright and contact information isn’t stylish at the bottom of the page anymore? Or you just want to move that sidebar where your "footer" is? You’ll have to rework the markup, move code around and waste time. This takes a valuable function of out CSS, you should be able to completely redesign the layout of your site without touching the markup (unless you want to add stuff, of course). That’s the true power of CSS.

Advanced Semantics

Andy Clarke proposed that we actually look at the content contained in these divs before give them labels and lock them into a role that could change in the future.

Andy’s suggestion
<div id="branding"></div>
<div id="nav"></div>
<div id="content">
  <div id="content_main"></div>
  <div id="content_sub"></div>
</div>
<div id="site_info"></div>
My edits

I’ve made some suggested changes to this code, I’ll get into the why of that in a little while, but for now, here’s how I changed it:

<div id="branding"></div><!--/branding-->
<div id="nav"></div><!--/nav-->
<div id="content">
  <div id="content-main"></div><!--/content-main-->
  <div id="content-sub"></div><!--/content-sub-->
</div><!--/content-->
<div id="site-info"></div><!--/site-info-->

What information can we gather from these div names? (Let’s just look at the 3 we’re talking about)

Branding

Logo, tagline, topics, information and graphics that brand this as an individual can be found in a div named "branding". Best of all, it gives no positioning–relevant information, so in the future (or present) this area can be moved and modified in any way. As long as the content stays meaningful to branding information (which is not usually something that changes in a redesign/realignment), all will be well on the web.

Content-sub

This is old "sidebar"; "content-sub" is labeled as secondary content, it can be positioned anywhere, and will most likely continue to be secondary information in relation to "content-main". And both are contained in a div labeled as "content". You can always add more elements in there like "content-level-three" to accommodate a growing site. But, I find that "main" and "sub" usually cover everything.

This will clean up your style sheet as well:

#content{}
#content-main{}
#content-sub{}
Site-info

"Site-info" replaces the old "footer". The footer usually contains content about the site: archives, copyright, maybe a contact link, etc. And there’s no rule that says that information needs to be at the bottom of the page (there isn’t, I checked). It’s fine if it’s there, that’s where mine is, but in the future if you want to move it the div name will stay semantic and meaningful.

The changes I made

I made some changes to Andy’s code for a few reasons:

  • I can never leave well enough alone.
  • I always close out my divs with a comment telling me which div got closed so there’s no confusion in the future.
  • The underscores: I switched out the underscores with dashes because I came across an article about using underscores in CSS.

In old browsers the underscore in ID and class names had to be escaped like:

p.urgent\_note {color: maroon;}

Or there can be some bad layout problems. Now, this is a big "Who give a crap" in today’s web since no one uses these old browsers anymore, but I see it as a small change to my CSS to make it slightly more degradable just in case some strange user comes by. And it’s really no extra work to do this, which makes it even better.

Closing

I’ve been using this technique for a while now and I love it. When I did my last redesign, it was just a straight style sheet swap. I don’t know if anyone remembers what that looked like, but this is totally different. It was very simple, fast and I hope some readers out there give it a try.

Thoughts? Want to tell me I’m wrong? I’d love to here it.

Tags: , , ,
Posted in Web Development, Web Standards | 18 Comments »

This Week in Links 11/11

Tuesday, November 11th, 2008

article image

Krop.com

I figured with the economy what it is and a lot of web folks looking for work I’d help out and post my favorite job site, Krop.com. I like this site for a few different reasons:

  • I found my current job there
  • They have a very simple interface
  • You can sign up for e–mail alerts based on a search term. When I was looking for a job in California I signed up to get e–mailed whenever a job came up in the search that had ", CA" in it. So I got all the California web jobs sent to me (and a few Canadian ones). It’s very nice.
13 Vital Skills for Every PHP Developer

There’s a lot about PHP that I just don’t remember off the top of my head and I need to look up. Luckily most of that is listed right here. This article contains things like Smarty, PayPal Integration, access control and caching with PHP.

jQuery Twitter Display

I’ll say it. I think jQuery is massively overused. But since you’re using it anyway and you want to display your Tweets, this is a plugin to do just that.

DocStoc

DocStoc is a repository for all kinds of documents. You can get everything from an example of a contract (hint hint to you freelancers) to the guitar tabs for "Smell Like Teen Spirit"

I’m not sponsored by any of these sites or services.

Tags: , , ,
Posted in Uncategorized | 1 Comment »

This Week in Links 11/5

Wednesday, November 5th, 2008

article banner

Good Practice in Pagination

Smashing put out a good article on a topic that I think gets overlooked a lot when dealing with user interface. A lot of times it’s taken for granted, but pagination is an important page of the UI.

Freshbooks

Freshbooks is a service for the freelancer out there. It’s a fast way to track time and invoice your clients. I currently use Harvest, but I really like how Freshbooks deals with invoicing

35 Fireworks Tutorials

I use fireworks and there are NO good tutorials out there form e. So I was THRILLED to find this link. Photoshop is great and all, but it’s a program meant for web & print design. Being a person who doesn’t do any print design, a lot of the features in Photoshop are just cruft to me, so I happily use Fireworks.

Freelancer Magazine

Freelancer Magazine in the newest edition to my feed reader. THey have all sorts of great advise for the freelancer and a lot of stuff that’s just good to know. Highly recommended.

I assure you, I’m not sponsored by any of these sites or services.

Tags: , , , ,
Posted in News, Web Development | 2 Comments »

|

New from the blog

Are My Sites Up? authenticjobs.com