Title: Tech Times
Email not displaying correctly? View it in your browser.

Issue 206: September 9, 2008  Tips, Tricks, News and Reviews for Web Coders

Introduction

Andrew Tetlaw"...we've implemented every property in CSS 2.1 and are closing in on our goal of complete support for the CSS 2.1 specification by the time we release."

If you were to guess who recently made that statement you'd be forgiven for thinking it came from the Opera, Safari, or Firefox team; they have always seemed to be the most standards-conscious browser vendors. In fact, this quote comes from Doug Stamper of Microsoft, regarding Internet Explorer 8.

It seems the very thing web designers have been asking for -- mature support for CSS2.1 across all major browsers -- is actually about to happen. Back in Tech Times #185, Kevin Yank wrote about what this would mean to web designers in Table-Based Layout Is The Next Big Thing. In short, he said that CSS tables would become the best tool for CSS page layout.

There were mixed reactions to that article, particularly on the point of row and column spans. HTML tables let you create cells that span multiple rows or columns, but CSS tables don't provide that same freedom.

Well, in his research for an as yet unannounced, potentially controversial book on CSS, Kevin has found an answer. In this issue, he returns to the topic of CSS-table layouts and describes a method for simulating row and column spans.

Top

ektron
What do you want your website to do?

Ektron CMS400.NET gives you all the tools you need to create, deploy, and manage your Web site - all rolled into one application

  • Corporate Web Site: Put authoring in the hands of your subject matter experts
  • Intranet: support inter-departmental communication
  • Social Networking Platform: Make your site an online destination
  • Web 2.0 Toolbox: Make your site more interactive & engaging
  • Ektron Starter Sites: Build your site faster and smarter.
Version 7.5 now available! Watch an INSTANT DEMO or download a FREE TRIAL now

Summary

Rowspans & Colspans in CSS Tables

by Kevin Yank

If you’ve had experience building layouts using HTML tables, you’ll be familiar with the use of the colspan and rowspan attributes of the td element. These attributes offer complex possibilities to a simple table, enabling cells to span columns and rows.

CSS tables lack any concept of row or column spanning, making it trickier to use one single layout structure than what might have been possible when using tables. However, similar layouts can be achieved by using nested CSS tables.

Of course, nested tables are not a perfect solution. When you want to match the dimensions of cells across nested tables, for example, things can get messy in a hurry, and the extra <div> tags really start to add up.

As it turns out, it’s also possible to simulate row and column spanning using absolute positioning of table cells, in many cases. In this example, we’ll make the second cell of the first row of a table span both rows of the table (as if it had a rowspan of 2). First, let’s take a look at the HTML code:

<div class="tablewrapper">
  <div class="table">
    <div class="row">
      <div class="cell">
        Top left
      </div>
      <div class="rowspanned cell">
        Center
      </div>
      <div class="cell">
        Top right
      </div>
    </div>
    <div class="row">
      <div class="cell">
        Bottom left
      </div>
      <div class="empty cell"></div>
      <div class="cell">
        Bottom right
      </div>
    </div>
  </div>
</div>

You’ll notice that we’ve wrapped our table div in an extra div with a class of "tablewrapper". This extra div is needed to provide a CSS positioning context—which we create by giving it relative positioning:

.tablewrapper {
  position: relative;
}

According to the CSS spec, we should be able to simply apply relative positioning to the table div, but current browsers don’t seem to support this.

Read on below for the CSS code that makes the row span possible.

Top

Tech Alert :: Geeks love WebHostingBuzz!

Maintaining a website can be both fun and sometimes frustrating especially if the web host does not catch up to your needs. The owners behind WebHostingBuzz have experienced it all.

We have been there and done it. We know what YOU want when it comes to running a script oriented website. We know what YOU want when it comes to value for your web hosting dollars. We host over 150,000 domains across the globe. Surely we can host yours!

Host unlimited websites under one account. Get a free domain name for life, tons of web space and transfer for only $40 per year.

Now, we can use absolute positioning to control the size and position of the div with class "rowspanned cell":

.cell.rowspanned {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100px;
}

With the top and bottom properties both set to zero, the cell will stretch to fill the full height of the table, simulating a row span. Depending on the needs of your layout, you could use different values for top and bottom, or even set the cell’s height directly to achieve other row-spanning layouts.

You also need to specify the width of the cell. Usually, the easiest way to do this is just to set its width property, but depending what you know of the dimensions of surrounding table cells, you could also do this by setting left and right.

Since the positioned cell doesn’t actually span multiple rows of the table, the table must still contain a corresponding cell in each of the other rows. These cells are simply empty placeholders, though; note the div with class "empty cell" in the HTML code above. The function of this cell is to hold open the space that will be occupied by the “spanned” cell, so we must ensure its width matches the width we specified for the "rowspanned cell":

.cell.empty {
  width: 100px;
}

And that’s all there is to it! To complete the style sheet for this example, we need only set the appropriate display property values, and add some borders so we can see what’s going on:

.tablewrapper {
  position: relative;
}
.table {
  display: table;
}
.row {
  display: table-row;
}
.cell {
  border: 1px solid red;
  display: table-cell;
}
.cell.empty
{
  border: none;
  width: 100px;
}
.cell.rowspanned {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100px;
}

In essence, by using absolute positioning we are telling the browser, “Let me handle the layout of this table cell—you take care of the rest.” Here's what the results look like:

This example works in all major browsers except for Internet Explorer 7, and also works in the current IE8 Beta 2 release.

What do you think? Can you see yourself switching to CSS tables for layout as your Internet Explorer users make the move to IE8? Leave a comment to let me know:

kev _javascript_ & CSS Blog: Stylish Scripting
by Kevin Yank

Rowspans & Colspans in CSS Tables

Top

101 Ready-to-use PHP Solutions

The PHP AnthologySave time, and eliminate the frustration of completing PHP5 tasks, with this comprehensive collection of 101 ready-to-use solutions. Learn to:

  • Build functional forms, tables, and SEO-friendly URLs.
  • Reduce load time with client-and server-side caching.
  • Produce and utilize web services with XML.
  • Secure your site using access control systems.
  • Easily work with files, emails, and images.
  • And much more... Too much to mention here!

Click here to order your copy directly from sitepoint.com today!
Bonus: Get a PHP Quick Reference poster, a $9.95 value

See you next week for another issue of the Tech Times!

Kevin Yank
[EMAIL PROTECTED]
Editor, The SitePoint Tech Times

Top




Latest Release

The Ultimate HTML Reference

Book

Tell me more..

Free Book Samples

Simply _javascript_
Simply Rails 2
Build Your Own Database Driven Website Using PHP & MySQL, 3rd Ed.
The PHP Anthology, 2nd Ed.

New Technical Articles

Build a Yahoo Music Mashup with Adobe AIR

Jack HerringtonEver wanted to do more with your iTunes library? In this tutorial, Jack shows you how you can leverage the Yahoo Music API to create video timelines of your favorite artists—and get your hands dirty with Flex and AIR along the way! Oh, and there are more books to be won...

Full Story...

 Techy Forum Threads

 More Techy Blog Entries

Web Tech

SitePoint Technical Editor Might Just Be Your Dream Job
12 comments

ColdFusion

The release of ColdFusion 9...

News & Trends

Scalability: Traction from a Slippery Beast
5 comments

Help Your Friends Out

People you care about can benefit from the wealth of information on new and maturing technologies available on the Internet. Help them learn how to do it by forwarding them this issue of the Tech Times!

Send this to a friend
You are subscribed as : [EMAIL PROTECTED]

Unsubscribe [EMAIL PROTECTED] from this list.

Manage your subscriptions.

View the newsletter archives.

Mailing Address:
48 Cambridge St, Collingwood, VIC, 3066 AU
Phone: +61 3 9090 8200
© Copyright 2008 SitePoint. All rights reserved.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "MIS.Suresh" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/missuresh?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to