HTML Tables vs CSS & divs - examples/help

Reply

Join Date: May 2009
Posts: 23
Reputation: FeralReason is an unknown quantity at this point 
Solved Threads: 0
FeralReason FeralReason is offline Offline
Newbie Poster

HTML Tables vs CSS & divs - examples/help

 
0
  #1
Jul 2nd, 2009
Admittedly, I'm new to CSS but I am having some difficulty converting tables to CSS. Here is a CSS example for a simple 4 cell table that works fine -- but only without the DOCTYPE declaration (any DOCTYPE declaration)!

Does anyone know what, if anything, I am doing wrong ? Any help would be appreciated.

(Also I would like to see any successful examples anyone would like to post.)

HTML and CSS Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html>
  5. <head>
  6. <style type="text/css">
  7. .TblContainer {
  8. width:400px;
  9. font-family:Arial,Helvetica,sans-serif;
  10. background-color:yellow;
  11. border:1px solid #CCCCCC;
  12. margin:3px 3px 3px 3px;
  13. }
  14.  
  15. .Row {
  16. margin:3px 3px 3px 3px;
  17. }
  18.  
  19. .Cell {
  20. color:#000000;
  21. border:1px solid #CCCCCC;
  22. float:left;
  23. font-size:16px;
  24. text-align:center;
  25. width:49%;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div class="TblContainer">
  31. <div class="Row">
  32. <div class="Cell">Cell 1</div>
  33. <div class="Cell">Cell 2</div>
  34. </div>
  35. <div class="Row">
  36. <div class="Cell">Cell 3</div>
  37. <div class="Cell">Cell 4</div>
  38. </div>
  39. </div>
  40. </body>
  41. </html>
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 11
Reputation: siji44 is an unknown quantity at this point 
Solved Threads: 1
siji44 siji44 is offline Offline
Newbie Poster

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #2
Jul 2nd, 2009
HTML tables are used for displaying tabular data on the page.
Div's are used to build the entire layout of the page. It gives more layout control using CSS.

And i dont see any thing wrong with your above code and it works fine with my browser . But i recommend you should use Html tables itself as you want just tabluar data.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 23
Reputation: FeralReason is an unknown quantity at this point 
Solved Threads: 0
FeralReason FeralReason is offline Offline
Newbie Poster

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #3
Jul 2nd, 2009
Originally Posted by siji44 View Post
HTML tables are used for displaying tabular data on the page.
Div's are used to build the entire layout of the page. It gives more layout control using CSS.

And i dont see any thing wrong with your above code and it works fine with my browser . But i recommend you should use Html tables itself as you want just tabluar data.
Thanx for the reply. I understand (and actually agree with) the argument but (call it self-education) I am still interested in determining to what extent css can do tables without using table tags.

In the code shown, the background should be yellow -- showing that the TblContainer div is in fact containing everything. It only shows up as a yellow band at the top of the cells in IE, FF and Chrome when I load it -- unless I delete the DOCTYPE. Are you seeing something different ?

Thanx for your help.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 11
Reputation: siji44 is an unknown quantity at this point 
Solved Threads: 1
siji44 siji44 is offline Offline
Newbie Poster

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #4
Jul 3rd, 2009
I have checked your code. The problem is with the positiong of floated div's in a nested div. Please add these css:-

.Row{
margin:3px 3px 3px 3px;
clear: both;
}


.Cell {
	color:#000000;
		border:1px solid #CCCCCC;
		float:left;
		font-size:16px;
		text-align:center;
		width:49%;
                   margin-right:3px;	}


I hope this will help you and for detailed explanation please go through this site:
http://www.positioniseverything.net/easyclearing.html
Last edited by peter_budo; Jul 6th, 2009 at 11:09 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 23
Reputation: FeralReason is an unknown quantity at this point 
Solved Threads: 0
FeralReason FeralReason is offline Offline
Newbie Poster

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #5
Jul 3rd, 2009
Originally Posted by siji44 View Post
I have checked your code. The problem is with the positiong of floated div's in a nested div. Please add these css:-

.Row{
margin:3px 3px 3px 3px;
clear: both;
}


.Cell {
color:#000000;
border:1px solid #CCCCCC;
float:left;
font-size:16px;
text-align:center;
width:49%;
margin-right:3px; }


I hope this will help you and for detailed explanation please go through this site:
http://www.positioniseverything.net/easyclearing.html

Thanks much for your replay. When I add the "clear:both" line the lower edge of the container moves down to contain the first row but not the second. Adding the "margin-right:3px" statement causes all 4 cells to stack vertically rather than appear 2 to a row horizontally. However, your reference was golden !

The reference has a link to a more recent article on this problem, offering up several solutions. The most elegant is to place an "overflow:auto" in the container. This works perfectly without any other changes.

One other solution that came from my son in San Francisco is to simple set the height of the row. Apparently floating the cells causes the container to lose track of the height of what it is enclosing.

All-in-all: "overflow:auto" seems to be the best solution.

Thanx much.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: HTML Tables vs CSS & divs - examples/help

 
1
  #6
Jul 8th, 2009
You are designing for the quirks mode of the browsers without the doctype. If you are in quirks mode, the browsers do weird things.

Standard mode puts the surrounding styles (margin, border, padding) OUTSIDE the width and height declarations, so you have to leave extra space for them.

Don't use pixels and points. Use percents and em, so the page is compatible with multiple screen resolutions.
Last edited by MidiMagic; Jul 8th, 2009 at 2:26 am.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 23
Reputation: FeralReason is an unknown quantity at this point 
Solved Threads: 0
FeralReason FeralReason is offline Offline
Newbie Poster

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #7
Jul 8th, 2009
Very good! Never heard of quirks mode but (after a short search for my education) this certainly explains the problem. (http://www.quirksmode.org/css/quirksmode.html - section on overflow:visible)

Thanx for the advice !
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 276
Reputation: kanaku is on a distinguished road 
Solved Threads: 15
kanaku's Avatar
kanaku kanaku is offline Offline
Posting Whiz in Training

Re: HTML Tables vs CSS & divs - examples/help

 
0
  #8
Jul 11th, 2009
When you 'float' an element, it's like you're taking it on a higher plane. (think of the page as the airport and the floated div an... err... flying airplane)
Since the elements contained by the main div are all floated, the main div, in effect, has no 'content'. So all you see is its borders (the small band at the top).

The overflow: auto is a good solution... provided the 'overflowed' div doesn't span 100% of the page width.
If your overflowed div has 100% width, and the page exceeds one 'page length', the scrollbar that appears on the right causes the div have a less than 100% displaying area. So some browsers will display a horizontal scrollbar. Which is ugly. =(
I've had to reduce the width of my main container divs due to that problem.
And I'm still waiting for the table-cell, table-row, etc. values for the display property to be supported by all browsers.
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.

Visit this thread
if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC