471,862 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,862 software developers and data experts.

how to create table based structure using div tag

254 100+

I want to create table based structure but without using table tag. I want to use div tag. How can I do that?
Apr 8 '08 #1
5 75291
490 Expert 256MB
Firstly define what you mean by a table based structure.

If you want a table based structure (like a grid of data) then surely you would use a table.

If your talking about for layout, then you would use CSS.
Apr 8 '08 #2
254 100+
Firstly define what you mean by a table based structure.

If you want a table based structure (like a grid of data) then surely you would use a table.

If your talking about for layout, then you would use CSS.
No I am talking about layout then how could I do it?
Apr 8 '08 #3
490 Expert 256MB
Heres a good article

Apr 8 '08 #4
Heres a good article
Yeah, getting the 5/box-3/col set with fixed heights is trivially easy. Try getting 'equal columns' if you don't fix the height, however. That's the challenge. It's been so for many years, and is well known. How to get a table /grid without any table tags, using only css?

What happens is that the columns only go down as far as the content pushes them, much like the old NN not responding to cell/column widths if there wasn't enough text in the cell. One can provide a common background and give the impression of full length and equal columns. But try to color one column, try to color the shortest column, and one instantly sees the problem with css, used that way.

But it's an old way with the arrival of FF 2 and Opera 9. Sure IE6 is out of luck, here. But IE6, good for its day, is subject to TOO MANY hack-arounds as it is.

In FF and Opera, you simply use the CSS2 table stylings. Now, admittedly, these are presently designed to work with HTML table tags. But that said - two will work just with any element. These are display: table-row and display: table-cell. You can even make up your own element name, or just use class.

First, the way one might have done it, before, and that works in IE6. It's limited. Even FF didn't seem to like the percentage column widths. So fixed widths are used for the columns. One floats left. The middle has left and right margins to keep it out of right and left columns. And the right column is positioned absolutely to the right border. Since the columns don't expand vertically, a common background is used for all three columns. Here the footer attaches to the middle column. It could be assumed that the middle will always be the tallest. But should either the left or right have more content and become taller, then the footer will still cling to the bottom of the middle column, and will overlap the longest column in an ugly way. It's a lot of compromises, assumptions. But in this way, it works.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>CSS 'equal columns'</title>
  5. <style>
  7. .containdiv {
  8. width: 100%;
  9. display: block;
  10. border: 1px solid #000;
  11. background: #afa;
  12. }
  14. .col {
  15. padding: 1em;
  16. }
  18. .col1 {
  19. float: left;
  20. width: 200px;
  21. }
  23. .col2 {
  24. display: block;
  25. top: 0;
  26. margin-left: 220px;
  27. margin-right: 230px;
  28. }
  30. .col3 {
  31. width: 200px;
  32. position: absolute;
  33. right: 0;
  34. top: 0;
  35. }
  37. .ftr SPAN, .hdr SPAN {
  38. display: block;
  39. padding: 0.5em;
  40. }
  42. .hdr {
  43. border-left: 1px solid #000;
  44. border-top: 1px solid #000;
  45. background: #ffa;
  46. }
  48. .ftr {
  49. border-left: 1px solid #000;
  50. border-bottom: 1px solid #000;
  51. border-top: none;
  52. clear: left;
  53. background: #ffa;
  54. }
  56. </style>
  57. </head>
  58. <body>
  59. <div class="containdiv">
  61. <div class="hdr">
  62. <span style="text-align:center;">Header</span>
  63. </div>
  65. <div style="position:relative;width:100%;">
  66. <span class="col col1">some text</span>
  68. <span class="col col2"> In the second Oration, delivered next day, he dwells on the Sacrament of Baptism and its spiritual effects; and takes occasion to reprove the then still prevalent practice of deferring Baptism till the near approach of death. He likewise dwells on the truth that the validity and spiritual effect of the Sacrament is wholly independent of the rank or worthiness of the Priest who may minister it
  69. </span>
  71. <span class="col col3">some text</span>
  72. </div>
  74. <div class="ftr">
  75. <span style="text-align:center;clear:both;">Footer</span>
  76. </div>
  78. </div>
  79. </body>
  80. </html> 
So that's for IE, FF and Opera. It should work in all three. However, if one wanted separate colors in each column, one would be out of luck in IE6. So here's the change, using table-cell from CSS2. All one does is substitute the following rules for the same rules above. Try it.

Expand|Select|Wrap|Line Numbers
  1. .containdiv {
  2. width: 100%;
  3. display: block;
  4. border: 1px solid #000;
  5. }
  7. .col {
  8. padding: 1em;
  9. display: table-cell;
  10. }
  12. .col1 {
  13. width: 10%;
  14. background: #dde;
  15. }
  17. .col2 {
  18. background: #ede;
  19. }
  21. .col3 {
  22. width: 10%;
  23. background: #edd;
  24. }
Now, all of a sudden, it looks like a table. Full-floating. Percentage widths. Each cell full height. Each cell has its own color. And each cell is full top to bottom, touching header and footer. Again, won't work in IE6. But one would presume that this just above would be in the main external stylesheet. And those previously that worked in IE6 would be in whatever 'iefix' stylesheet that is separately loaded in. Everyone does that, these days. IE6 is the 'downscale' browser that requires some fix-up and touch-up. So one would just include the first col and container styles in the iefix stylesheet, and it would display with all the compromises, but the same HTML would display properly (after a fashion) in IE6.
Apr 8 '08 #5
490 Expert 256MB
Sevry just about got more detail that i would've given! Bookmarking for next time!
Apr 9 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by J West | last post: by
6 posts views Thread by Bruce | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.