Jim Barraud

Category: ‘WebDev’

The Magical CSS Table Cell

Back in the dark ages of web markup, the most reliable way to layout anything was by using a table. One of the best utilization’s of the table-based layout was laying out a form. We’ve come a long way in breaking away from laying out forms in tables. There are plenty of techniques for doing this that have already been discussed, so I’m not going to rehash that. Some would even argue that tables are still the most reliable to layout forms.

There’s one aspect of table based layouts that has eluded the non-table based layouts. The magic of the table cell. Or more specifically, the magic of multiple table cells working in unison. If the width of one table cell expands, all the others in the column follow along. This is especially useful when it comes to laying out forms. When laying out a form with tables, one cell is defined as the form label and the adjacent cell is the actual form element. This is repeated down the table columns for additional form elements. Instead of having to explicitly define a width for the label cell, the form label widths can be defined by width of the cell with the longest text label. This helps keep the form elements and form labels properly aligned without having to define an explicit width for each individual form label.

When it comes to non-table based layouts, each element is independent of the other. If the text size in one form label is longer than the others, the other labels don’t care. They stay right where they are with their own defined width. To get the form labels and elements properly aligned, you need to explicitly define the width of all your labels. Which can be a totally acceptable solution if you know what the content of every form will be and how long the average form label will be. But when it comes to dynamic systems that may have a single form layout framework used for all forms throughout the system, you may never know what text is thrown into the form labels or how large the form may be. Leaving you’re explicitly defined form structure in a highly dynamic system to become inconsistent at times.

Two forms with explicitly defined widths with varying length text labels

So why go with the non-table based solution? Flexibility. The flexibility you have with your form layouts far outweigh this one issue. Want you’re labels to the left of your form element instead of the top? Or maybe on the right instead of the left? It’s a matter of just changing the CSS declarations related to the label. To do that with a table based structure, you need to restructure the table. And within dynamic systems that may have that form distributed through several files, you could be in for a lot of hurt in updating that table.

Which brings us back to the special magic of the table cell. For a long time it’s been defined in the CSS 2.1 specification that the “display” property could not only define the layout of an element as block or inline, you could also define it as table, table-row, table-cell and various other table properties. These table based display properties allow you to define other elements, such as divs, to take on the structural properties of these table elements. But support for these property values has been spotty or non-existent in most of the major browsers. But this will be changing with the upcoming crop of new browsers.

In trying to come up with optimal form layout markup for one of our clients at the Hive, I wanted to find a solution for the form label issue described above. The following is some sample markup of a simple form.

 <div class="myForm">
    <div class="row">
      <label for="text1">Label</label>
      <input type="text" name="text1" />
    </div>
    <div class="row">
      <label for="text3">Here's a super long label</label>
      <input type="text" name="text3" />
    </div>
    <div class="row">
      <label for="text2">Another label</label>
      <input type="text" name="text2" />
    </div>
  </div>

The goal is for all the labels to be align flush right against the form elements, have both the form elements and labels aligned vertically, and have the overall form aligned to the left of the containing element. But I don’t want to assign a width to the label because due to the dynamic nature of the form, I won’t know what the length of the label text will be or how many elements may makeup the form on a given page. For example, if I define the label width as 200px and there’s only two form elements with the labels of First and Last, the form won’t be aligned flush left of the containing element due to the large label width and short text strings within it.

This is where the table based display properties come in handy. I’m able to layout my form using semantic markup, but I’m then able to define that semantic markup to use some of the layout qualities of a table. I’ve essentially defined a sudo table by declaring these table based values in the display properties of various CSS element declarations.

.myForm{
  display: table;
}
.row{
  display: table-row;
}
label{
  display: table-cell;
  text-align: right;
  padding: 0 5px 10px 0;
}

This works in Safari 3.1, Opera 9, Firefox 3 (RC 1) and the IE8 beta. The IE8 beta is a little flaky, but it’s an early beta and there’s still more work to do on the CSS front for IE. Firefox 2 support is partial and IE6/7 support is non-existent. So use of this technique will depend on which browsers you choose to support.

Is this a solution to be used every time you create a form? No, of course not. This may even be an edge case for most people as their forms may be pretty straight forward. But there often times I find myself with the need to have the actual text of the label define width of the form labels. As with all design decisions, it really depends on the context within which your using your form and the problem you’re trying to solve.

You can view example of this technique here

CSS (in)Efficiency

Shaun Inman has an interesting blog post proposing CSS parent selectors. Something a lot of people (including me) have been begging for. The proposal on the surface looks good and sound, but when you dig into the comments, apparently it’s a lot more complicated. Take particular note of the responses from Dave Hyatt, he’s the lead developer on Webkit. You find out why it’s not something that will be implemented, and surprisingly (at least to me), how CSS selectors in general can get expensive in terms of performance. Especially for large scale web apps.

I was always with the understanding that CSS selectors were the most optimal route for CSS definitions, since your getting very specific about the element you want to style and not adding a ton of IDs and classes to your HTML. Apparently when it comes to performance the opposite is true. While it seems this performance hit isn’t noticeable on smaller scale sites, it can become a performance bottleneck on larger scale web-apps. The problem is I don’t know what the degree of the performance hit is and how complicated your site needs to be for it to be noticeable. I’m also not clear on if this is a browser specific issue. Browsers that are referenced include Safari and Firefox, but does IE or Opera suffer from this as well?

If this issue gets any more prominence, I’m sure some performance tests strictly dealing with CSS will start to emerge. As of right now, it’s something take note and of and keep on eye on.

Update: One of my partners in crime at Media-Hive, Mr. Jon Sykes, has posted a 3 part series on testing the above issue. Testing CSS Performance, Testing CSS Performance pt.2, and More CSS Performance Testing.

Email Standards Project

HTML formated emails are considered the spawn of the devil by some. And by others it’s considered the next evolutionary step in email. Whichever side you sit on, both agree the HTML formated emails aren’t going anywhere and will only become more popular.

From a developers point of view, creating an HTML formatted email can be about as fun as root canal. Why? Because as opposed to browsers, which there are only 2-3 core browsers (calm down fringe browser people), there are 10-15 core email clients. The level HTML and CSS support varies greater then the level of support the browsers had in the dark days of the browser wars. To encourage browser makers to comply to the basic set of web standards support, the Web Standards Project was created. This was (and still is) a group that lobbied browser makers to support web standards. Proving that it was not only for the benefit for web developer, but also for end users and the browser makers themselves. They have been extremely successful their efforts.

The Email Standards Project aims to do the same for HTML/CSS standards support within email clients. They’ve just launched their official site which contains info on why this matters, what you can do, and a list of popular email clients and their current level of standards support. They’ve even created an Email Standards Acid Test for testing the level of support of each email client.

I encourage anyone who has to create HTML formated emails or anyone who relies on them as promotional tools for their business to visit the Email Standards Project and show your support.

Safari 2 In Leopard

Safari 2 In Leopard

Interesting… If you use one of these custom Safari 2 builds in Leopard michelf.com/projects/multi-safari/ , you get the older Web Clips icon. It’s non-functioning though.

DIANE von FURSTENBERG

Our latest project at Media-Hive has just launched; the website for Diane von Furstenberg. Our role, more specifically for the Hive, was the eStore portion of the website. The eStore is built upon ATG’s Commerce onDemand platform (of which we are an implementation partner). Our task was to implement a new design, created by Sweden Unlimited (who also created the marketing side of the website) into the Commerce onDemand platform. We were integral in creating the base Commerce onDemand HTML/CSS framework so it was a natural fit for us to implement the new DVF design into the platform. My personal role was the HTML/CSS integration of the new design as well as the Scene7 integration which allows for product image zooming and alternate view display.

DIANE von FURSTENBERG

A Little Touch Up

This past week I’ve been on vacation spending quality time with the family. In the downtime between the quality time, I’ve been able to work on finishing up the small redesign I’ve been working on. Nothing too drastic, but it’s something I’m much happier with. And it’s also a design I’ll be refining as time goes on.

In addition to the new look and feel, I’ve also redone the underlying markup. Posts are now marked up in the hAtom microformat and other microformats such as hCards are sprinkled throughout. At the top of the page is my latest Twitter post which could contain any random thought that passes through my head.

I’m sure there may be small visual bugs here and there (or something I’ve just forgotten), but if you experience and issues or see anything glaringly wrong, let me know.

Are you POSH?

Creating semantic HTML has been a way of life for most modern web developers for past 4-5 years. At least it has been for me. With all the benefits that come along with coding your HTML this way, you would think it was an easy sell. Convincing other web developers that upgrading their techniques and skill set to this more modern way of markup. And convincing companies it was in their best interest to code (or re-code) their sites this way. But it wasn’t. Lack of time, money, resources, understanding… pick your poison.

These days more people “get it”. They understand the this is the way forward. And they see the benefits when this modern way of creating semantic HTML is put into action. But not everyone does, so there still some education to be done. You still need to give the the modern semantic HTML speech you’ve given a hundred times. And for those who are in the semantic HTML club, you’re still referring it to “modern semantic HTML that follows web standards” (or a variation thereof) when talking to you buddies.

Now there’s a new term that seems to be blazing a trail through various web development blogs to describe this modern way of coding. POSH. Plain Old Semantic Markup. It’s looking to make a brand name out of what we do everyday. Basically what AJAX did for the XMLHttpRequest object and all that it makes possible. You say “AJAX” and people know what you’re talking about without you having to explain further. Unless of course, they don’t know.

Personally, I like the idea of having a brand name for what we do. Look what AJAX did for “asynchronous server request that doesn’t require a browser refresh”.

So what about the term “POSH”? Is this the best we can do? I can’t think of the term “POSH” without thinking of the Spice Girls. Not sure what that says about me, but lets not go there right now. On the other hand, no one could talk about AJAX without thinking about the abrasive cleaning agent, but that seems to have passed. Time will tell to see if this sticks or not. If it does, I may just stick to “semantic HTML”. Like the cool kids who still refer to AJAX as “XHR”.

HTML5 Proposal to the W3C

The same day I decide to leave HTML Working Group due to the flood of emails and general lack of organization and direction; Apple, Mozilla, & Opera also decided enough is enough. They’ve filed a formal proposal for the current W3C HTML Working Group to adopt the work the WHATWG has already put into HTML5. This will act a starting point for further discussions of the HTML5 specification. We’ll see what the co-chairs have to say about this and if it’s accepted.

HTML unWorking Group

I was initially excited about being a part of the HTML Working Group. I felt subscribing to the mailing list would offer an opportunity to contribute to the development of the HTML5 recommendation, or at the very least provide some insight into the process. So far, I have gained a bit of insight into the process. It’s that there really isn’t one.

The amount of email that the list generates is completely unmanageable. A weekend can generate about 150 emails. And most of those emails are quite lengthy. There’s currently no real structure of what discussions should take place or how they should be handled. Actually, so far one quarter of the discussions have been about that fact. People trying to come up with a process. If you count all the discussions about how to handle the previous WHATWG efforts and how the new discussions will interplay with those, then it’s probably more like one third. I would have figured most of this would have been ironed out before setting up the new working group, but it hasn’t. The rest of the discussions are people pitching what they would and would not like to see in HTML5 and the ensuing arguments debate. Which is how it should be, but right now everything is posted very “willy-nilly”.

I’m sure most of these issues will resolve themselves in due time and real work will begin to get done (there’s some very smart people on this list). But unless you make the HTML WG your primary effort and don’t have a day job or a family, I’m not sure how anyone could actively participate. So I’ve unsubscribed from the mailing list. I’ll probably still keep tabs through the blog and the mailing lists online archives, but unsubscribing will remove the unnecessary “select unread, mark as read” workflow I currently have with dealing with the list.

Dear Google

The font size of the calendar module on the personalized homepage is very small. And just got smaller with introduction of your theme options for the personalized homepage (which I like, so thanks for that). The font-size declarations in the classes “eventChip”, “eventCell” and declared inline in the div with an ID of “createEventLinks27” are causing this unnecessary eye strain. Removing these declarations will make the font readable again (and the module useful again).

I am submitting this message in triplicate to ensure it reaches the proper personal. Also attached is a screenshot of the issue.

Small Font

Thank you for your time.

Update: Looks like Google has fixed the issue by updating the font sizes units from percentage to ems. Good show.

HTML Working Group(ie)

As an update to my previous post about the W3C HTML Working Group, I myself have joined. I’m coming at this from the perspective of an end user in what the working group will produce, the recommendation spec for HTML5. Not as someone who will implement the recommendations into the actual browsers, but as someone who lives day in and day out writing modern HTML markup. Since much of my work is centered around creating modern web applications and web applications is one of the main things to be addressed in HTML5, I’d be keen to add my 2 cents where appropriate.

I encourage anyone who feels that they may have something to contribute or has any strong opinions on where the language should or shouldn’t go, to sign up. It’s open to the public, so should something get decided you don’t agree with, you’ll have no one to blame but yourself. At the very least you’ll get a front row seat to the creation HTML5.

HTML ReGroup

Yesterday the W3C announced the formation of a new HTML Working Group with goal of updating the HTML & XHTML standards and bring them into the modern age. I personally have only 2 concerns with the new effort.

One, there won’t be a formal specification until Q3 2010. Yup, 3 1/2 years. And that’s if they keep to the timeline. But the other issue with that is once it’s a final spec, it’ll be another 2-3 years before these features are commonplace enough in the browsers for them to be useful. Of course the browser makers can be proactive and start implementing these features before the spec is a final recommendation. But considering the current recommendations (which are around 7 years old) still aren’t fully implemented, I’m not overly optimistic that will happen.

My second concern is that the co-chair of the new working group is Chris Wilson, the Group Program Manager for Microsoft Internet Explorer. My concern is not about Chris as an individual (I don’t know him), but that he’s employed by a leading browser manufacturer. And not necessarily because it’s Microsoft, I’d feel the same if it was someone from Mozilla, Opera or Apple. Having a browser manufacturer heading an organization with the task of updating the HTML standard seems like a conflict of interest. But considering the other co-chair is Dan Connolly from the W3C, there may be some checks and balances in place.

On a very positive note, the discussions related to the new recommendations will be open to all in a public forum. From the press release:

“Based on significant input from the design and developer communities within and outside the W3C Membership, W3C has chartered the group to conduct its work in public and to solicit broad participation from W3C Members and non-Members alike.”

So if you feel you have the expertise to contribute to the new HMTL/XHTML recommendations, sign up.

This is a very exciting development for anyone who works in the world of HTML. A lot has changed since the last recommendations were finalized in the ways we build web sites and web applications. It’ll be great to have markup that accounts for that and allows for developers to push it even further.

Just don’t let this take away from any CSS love :)

Kenyon Chapter

Kenyon Chapter

Created for the Kenyon Chapter of the National Association for the Education for Young Children, the site aims to provide it’s existing members with news and information on chapter happenings. The site also provides potential members with information about the chapter and how to join.

The original site was severely dated and very time consuming to update. The goals of the new site were for the design to be clean and for it to be easy to update by it’s board members. For this, I utilized the Wordpress content management system. This has allowed the Kenyon Chapter board members to easily update the content of the site, add new content, and add new pages themselves.

The site can be viewed here: http://kenyonchapter.com.

Screenshots are archived here