Jump to content

<div> instead of <table>

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
archive02

archive02

    Newbie

  • Members
  • PipPip
  • 10 posts
I've been suggested to use div tags instead of table tags to align objects on my webpage. As I understand div tags are only for setting styles though so how is it possible for me to align objects with div tags? For example, how could I create three columns and 2 rows with divs?



<table border=0>

     <tr>

        <td></td>

        <td></td>

        <td></td>

    </tr>

     <tr>

        <td></td>

        <td></td>

        <td></td>

    </tr>

</table>



#2
WillB

WillB

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts

archive02 said:

I've been suggested to use div tags instead of table tags to align objects on my webpage. As I understand div tags are only for setting styles though so how is it possible for me to align objects with div tags? For example, how could I create three columns and 2 rows with divs?

Okay, first of let me say that in my opinion it is not technically wrong to use tables in your layout. However, the technology has increased to a point where CSS does a better job. The code is cleaner, and separated from the actual html source code. It increases readability and actually makes updating and maintaining a site or page much easier. Plus tables take longer to render.
This site is a perfect example... Knoxville Life Church if you have firefox, disable the css when you get to this page, you will see that it is all div tags...

Morale of the story is learn CSS

Check out this section of the forum, it will answer your question: Div for positioning - HTML Help Central
Everything in Life can be solved with an 'If/Else' statement.

Life is like one big try/catch statement, nested within a loop.

-Will

[SIGPIC][/SIGPIC]

#3
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
My definition of the two tags:
div - For layout.
table - For showing different data.

The table tag has never been meant to be used for designing layout, or similar. It's meant to be used for showing data in an easy an effective way, while you should use the div tag, when you need to design layouts.

This is a heavily debated topic, so I'd like to hear other responses too. Maybe I am wrong?

#4
WillB

WillB

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
I would hope not. For the 7 years I've been a developer I've been told of the horrors of table-based layouts. I would like to believe that it is deprecated, CSS gives us that edge back. Or that one word: Flexibility.
Everything in Life can be solved with an 'If/Else' statement.

Life is like one big try/catch statement, nested within a loop.

-Will

[SIGPIC][/SIGPIC]

#5
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I don't think the table tag is deprecated yet. It's a fine solution for the purpose I mentioned in my last post; for showing different kinds of data. But I'll never use it for layout or anything else than showing data.

I don't think you can mix CSS into this discussion. CSS can be used on both table- and div tags. But you're right: CSS is way better, than putting the style right onto the tags (using the style attribute)

I can't say I like the table tag over the div tags, because their purposes are different. But let's say it in this way: in 99% of my time developing websites, I'm using div tags over table tags. And I'm using CSS always, of course.

#6
archive02

archive02

    Newbie

  • Members
  • PipPip
  • 10 posts
Can either of you show me an example using <div>s with the table structure I posted above?

#7
WillB

WillB

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
@void
I agree with you on that. 99% of the time, it seems as if most people stay away from table driven websites.

However, I am not indifferent to the idea. I have seen successfully written table-based layouts using CSS, as well as had to use them myself.

I'm not saying its down right wrong. I just think there are better ways to code. Obviously the <table> tag has it's uses.
I just am completely against using tables as a layout. Its such a horrible structure for your code.



@archive02
Check this section out. It will answer your question....
Div for positioning - HTML Help Central
Everything in Life can be solved with an 'If/Else' statement.

Life is like one big try/catch statement, nested within a loop.

-Will

[SIGPIC][/SIGPIC]

#8
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I'm following your "philosophy" too. I don't think that table-layouts are worser than if you had been using divs for the work, but in my opinion it's more "right" to use table and div in the "right" way. Data showing with tables, and layouts and other stuff with divs.

I had a similar discussion on a danish forum, regarding the two PHP-functions, echo and print. I'm not saying that it's bad to use print in a stand-alone statement, but echo would be better. echo don't return anything, print does. What shall you do with the return-value from print? Nothing! The value is always the same (1) - so why not just use echo? I think it's better to use echo in this situation. It also lead to a post on my blog, if anyone is interested (though my english is pretty bad.)

The last paragraph was slightly off-topic and irrelevant, but I think it fits in anyway. It kinda tells what I mean, in some way(?)

#9
archive02

archive02

    Newbie

  • Members
  • PipPip
  • 10 posts
Thanks, that thread link helped a lot. Particularly the code at the bottom:


<div id="menu">

<ul>

<li><a href="page.htm">Link</a></li>

<li><a href="page.htm">Link</a></li>

<li><a href="page.htm">Link</a></li>

<li><a href="page.htm">Link</a></li>

<li><a href="page.htm">Link</a></li>

</ul>

</div>

<div id="content">

blah blah blah blah blah blah blah blah 

blah blah blah blah blah blah blah blah 

blah blah blah blah blah

</div>


So the consensus here is to use CSS and divs rather than tables?

#10
Guest_Jordan_*

Guest_Jordan_*
  • Guests

v0id said:

I had a similar discussion on a danish forum, regarding the two PHP-functions, echo and print. I'm not saying that it's bad to use print in a stand-alone statement, but echo would be better. echo don't return anything, print does. What shall you do with the return-value from print? Nothing! The value is always the same (1) - so why not just use echo? I think it's better to use echo in this situation. It also lead to a post on my blog, if anyone is interested (though my english is pretty bad.)

The last paragraph was slightly off-topic and irrelevant, but I think it fits in anyway. It kinda tells what I mean, in some way(?)

It is funny that you had this discussion. It was asked here once: http://forum.codecal...51-why-not.html

Although it didn't get as in depth. You should post your return value argument in that thread.

#11
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

v0id said:

I had a similar discussion on a danish forum, regarding the two PHP-functions, echo and print. I'm not saying that it's bad to use print in a stand-alone statement, but echo would be better. echo don't return anything, print does. What shall you do with the return-value from print? Nothing! The value is always the same (1) - so why not just use echo? I think it's better to use echo in this situation. It also lead to a post on my blog, if anyone is interested (though my english is pretty bad.)

echo and print aren't functions they are language constructs :P

Anyway echo accepts parameters which allows you to avoid concatenation - hence increasing your codes performance. Stay tuned for more info :D

#12
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts

"Sidewinder" said:

echo and print aren't functions they are language constructs :P
echo and print are both functions, while they're still a part of a language construction, to make them do what they do. Or am I completely wrong? I'm not that much into PHP anymore, like I was before.

Edit: I realized that; you're right. I made some fast research, and yes, I see that those aren't functions. I better do some more research before I'm posting next time. :-)