Be Genius

Fork Me
Mugshot

Hi, I'm Bodaniel Jeanes.

I'm a Ruby developer from Brisbane, Australia

I work at Mocra where I hack on awesome code. Follow me, recommend me, and link with me.

Iterative HTML5 - Turning a comma-separated list into a semantic list

In the process of going through the redesign of
http://mocra.com, I keep finding better ways to make the HTML more semantic.

Jack Chen and I have been turning the design into HTML over the last few days and we’ve been striving to be as semantic as possible by taking advantage of new HTML5 elements and by separating the content further from the design code with all the new CSS3 selectors.

Here’s an example of something we just did to make the HTML cleaner and more meaningful, whilst still maintaining the look and style.

Here’s what we are styling:

Usually your HTML (or HAML in this case) would look something like this:

1
2
3
4
5
6
7
8
9
%footer %aside = link_to 'Dr Nic Williams', 'http://drnicwilliams.com/' , = link_to 'Bodaniel Jeanes', 'http://bjeanes.com/' , = link_to 'Jack Chen', 'http://chendo.net/' , = link_to 'Ryan Bigg', 'http://frozenplague.net/'

However, we can make this list of people more semantic by using an <ul> element and some CSS magic.

Here’s what the new HTML (HAML here) would look like:

1
2
3
4
5
6
7
%footer %aside %ul %li= link_to 'Dr Nic Williams', 'http://drnicwilliams.com/' %li= link_to 'Bodaniel Jeanes', 'http://bjeanes.com/' %li= link_to 'Jack Chen', 'http://chendo.net/' %li= link_to 'Ryan Bigg', 'http://frozenplague.net/'

And the CSS (Sass here):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
body footer aside padding-top: 6px float: left ul list-style: none margin: 0 padding: 0 li display: inline &:after content: "," &:last-child:after content: ""

New Design

Anyone visiting my actual site will realise quite quickly that there is a new design. It was designed by my girlfriend and put together by me over the last week or two. It is still not done, but it’s close enough for me to put it live for now.

One thing of note is that it is entirely HTML5 and CSS3. This is done partly as an intellectual exercise and partly as a statement affirming my belief in a semantic web. I am still learning what elements are right to use where, so if you look at the HTML source and say to yourself: “Hey, that’s not how that element is supposed to be used,” please do tell me and I’ll restructure it.

I’ve tried to keep classes and IDs to a minimum, using the full power of CSS3 selectors instead. In order to get the design out, I’ve cut a few corners I am not happy with and used some classes, but I plan on refactoring these occurrences soon.

So far the design looks and works perfectly in Safari 4 and FireFox 3.5. Before implementing comments, it was working perfectly in Safari 3 and FireFox 3, but I haven’t checked those yet. I am quite content ignoring IE and even older versions of FireFox and Safari, as my target audience is developers—web developers, specifically—and I fully expect them to be using the cutting edge of browser technology.

I’ve hacked Enki apart quite a bit to get the code highlighting the way I want, replacing CodeRay with Ultraviolet, then further modifying it to add my own line numbers in a way that made the line numbers not get selected when selecting the code. Now, my sin: I used tables. I’m sorry—I based it off CodeRay’s existing table code for line numbers but find this an utter violation of the semantic goal of this entire re-design. This will be very shortly replaced with <figure> elements and figure pre { display: table-cell; } to emulate the same design.

Also, somewhere between finishing the code highlighting, and working on the rest of the site, I broke code highlighting in FireFox. Will fix soon.

Now some code samples I am quite proud of:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<article> <header> <h1><a href="#" rel="bookmark">Article Title</a></h1> <details> <ul> <li><a href="#">0 comments</a></li> <li>tagged with <a href="/snow%20leopard">snow leopard</a></li> </ul> </details> </header> <aside> <time datetime="2009-07-09T05:34:00Z"> <a href="#" rel="bookmark"> <abbr title="July">Jul</abbr> 9<sup>th</sup> <abbr title="2009">'09</abbr> <sub> 5:34 am</sub> </a> </time> </aside> <section> <p>Article text</p> </section> <section> <h2 id="comments">Comments</h2> <ol> <li id="comment-17"> <a href="#" title=""> <time datetime="2009-07-01T12:47:33Z"> July 01, 2009 at 12:47 PM </time> </a> <h3>commenter says:</h3> <p>comment text</p> </li> </ol> </section> </article>

The CSS for the article is incredibly long, so I’ll just show off the fanciest CSS3, the part for the comment section:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
body > article > aside ~ section:last-of-type { margin-top:40px; } body > article > aside ~ section:last-of-type ol:first-of-type { border-top: 1px dotted #4B4B4B; margin-top:20px; list-style: none; width: 598px; margin-left: -20px; } body > article > aside ~ section:last-of-type ol:first-of-type li { border-bottom: 1px dotted #4B4B4B; padding: 20px; } body > article > aside ~ section:last-of-type ol:first-of-type li p { margin-bottom: 0; } body > article > aside ~ section:last-of-type ol:first-of-type li h3, body > article > aside ~ section:last-of-type ol:first-of-type li h3 a { color: inherit; font-size: 14px; } body > article > aside ~ section:last-of-type ol:first-of-type li h3 a { display: inline-block; padding-left: 15px; background: transparent url(/images/openid_icon.png) no-repeat 0 3px; } body > article > aside ~ section:last-of-type ol:first-of-type li time { font-size: 11px; } body > article > aside ~ section:last-of-type ol:first-of-type li:nth-of-type(2n+1) { background-color:#C5C5C5; } body > article > aside ~ section:last-of-type ol:first-of-type li table { margin-left: -51px; opacity:0.8; } body > article > aside ~ section:last-of-type ol:first-of-type li table caption { color: #000; } body > article > aside ~ section:last-of-type textarea { width: 100%; }

Please send screenshots of the design broken in some browsers. I do want to have a stab at making it work in as many browsers as possible. But for now, go modern or go bust!