2 Must-Know HTML Table Colum Features Any Webdeveloper Should Be Aware Of
I was reading up on the good old HTML specification and discovered a feature I had always wanted — and it’s already there:
Creating widths of columns that will work like percentages, but will also pay attention to any small, fixed-width columns.
Take a look at HTML’s proportional widths and amount alignment features.
Look at this from HTML specification of <COL> elements:
Authors may specify column widths in three ways:
- Fixed
- A fixed width specification is given in pixels (e.g., width=”30″). A fixed-width specification enables incremental rendering.
- Percentage
- A percentage specification (e.g., width=”20%”) is based on the percentage of the horizontal space available to the table (between the current left and right margins, including floats). Note that this space does not depend on the table itself, and thus percentage specifications enable incremental rendering.
- Proportional
- Proportional specifications (e.g., width=”3*”) refer to portions of the horizontal space required by a table. If the table width is given a fixed value via the width attribute of the TABLE element, user agents may render the table incrementally even with proportional columns.However, if the table does not have a fixed width, user agents must receive all table data before they can determine the horizontal space required by the table. Only then may this space be allotted to proportional columns.
Proportional widths! Nice. This means that you can create tables like this example (i have swapped the original HTML4 style to lowercase XHTML):
Once the (visual) user agent has received the table’s data: the available horizontal space will be alloted by the user agent as follows: First the user agent will allot 30 pixels to columns one and two. Then, the minimal space required for the third column will be reserved. The remaining horizontal space will be divided into six equal portions (since 2* + 1* + 3* = 6 portions). Column four (2*) will receive two of these portions, column five (1*) will receive one, and column six (3*) will receive three.
<table> <colgroup> <col width="30"/> <colgroup> <col width="30"/> <col width="0*"/> <col width="2*"/> <colgroup align="center"> <col width="1*"/> <col width="3*" align="char" char=":"/> <thead> <tr><td> ... ...rows... </table>
This leaves me with one big question: How is browser support for <col width=”2*”> ????
BONUS: Did you notice the little align feature ‘align=”char” char=”:” ‘ so that you can correctly align your decimal amounts? I was not aware of that either!
More info in W3C’s HTML4 specification “Calculating the widths of columns“
September 3rd, 2009 at 11:37 (GMT-1)
As far as I know no browser supports align=”char” — do you have other information?
September 3rd, 2009 at 23:03 (GMT-1)
I’ve never used this before but I want to try it very soon. Thank you for the post
September 3rd, 2009 at 23:51 (GMT-1)
im need this tutorial thankss!!!
September 4th, 2009 at 07:16 (GMT-1)
Proporational is new to me. I will have to use next time it makes sense.
September 4th, 2009 at 13:55 (GMT-1)
I like ur stuff on the HTML. I have to use it and then see what happens. Thanks for the info.
September 5th, 2009 at 10:55 (GMT-1)
Learning HTML is not so easy, but i am very confident that going through your post will help many people to know how easy it is. You have very well explained all the elements beautifully.
September 6th, 2009 at 10:09 (GMT-1)
This is a great find. I’d guess the reason its not more widely known is compatibility issues. Any update on your findings about that?
September 7th, 2009 at 04:01 (GMT-1)
I’m nt aware of the Browser support for column 2*. If you get to know please share with us.
Angeline @ marcus evans scam
September 7th, 2009 at 10:06 (GMT-1)
ops lose comment
thank a lot of information. may be useful. continue to increase the quantity and quality of your writing. the more qualified you are writing all the more delighted visitors to come back to visit. success always for you.
regard,
rusli zainal sang visioner
September 7th, 2009 at 12:47 (GMT-1)
Hello, First of all thank you for Providing great information about the HTML. THis will surely help newbies who want to know about the HTMl, im basically a Web Designing student, So i always do google searchs for the HTML tutorials, Etc and now found your site/blog and its GOOD
September 7th, 2009 at 12:47 (GMT-1)
Thanks for sharing. I’ve never used this before but I want to try it very soon. Thank you for the post & the sharing on HTML.
September 7th, 2009 at 16:57 (GMT-1)
is this also applicable to HTML5, HTML 5.0 is not a big hit but you know that transition is also another consideration
September 7th, 2009 at 23:44 (GMT-1)
Great information, written in a style everyone can understand. Thanks Jesper
September 10th, 2009 at 13:28 (GMT-1)
lol
i never heard this before
though i am gonna cross broswer check before testing it
September 28th, 2009 at 05:13 (GMT-1)
I love the idea of proportional tables, but how well supported is this among the various browsers?