tags:

views:

205

answers:

5

TD is a block element,

but displays like inline,say,several TDs within a TR display in the same line,

why?

+1  A: 

Because they are for tabular data.

Jonathan Sampson
Is there a more consistent way to explain that?
Shore
Shore, you might as well ask why links are clickable. It's inherent to their existence - it's the behavior they were created to display.
Jonathan Sampson
ok,ic .:)
Shore
A: 

TR = table row. How else would you want it to behave?

David M
+1  A: 

Because, that's how tables work.

Gab Royer
as tempted as I am to downvote, you are actually right :D
Here Be Wolves
One of the rare occasions "just because" is an adequate response :)
Jonathan Sampson
+14  A: 

TD's are actually not technically "block" elements. Have a look at the CSS display property. Cells are technically of type "table-cell" and they are a special case.

There is also another type of display called "inline-block" which can be useful.

Matt Bridges
upvoted, since it's almost exactly what I answered with, though I was a few seconds slower =) ...deleting
David Thomas
table-cell is a kind of inline-block,right?
Shore
It's similar, but not exactly the same. There are special layout considerations for tables that don't apply to explicit inline-block elements, although I can't think of any off the top of my head.
Matt Bridges
A: 

If you want a <td> to display as a "block," simply add another <tr> below the current <tr>. This will effectively make the <td> act like a block-level element.

Let's say you have a table like this:

<table>
    <tr>
        <td>Table cell A</td>
        <td>Table cell B</td>
    </tr>
</table>

And you want "Table cell B" to act like a "block." You could do this:

<table>
    <tr>
        <td>Table cell A</td>
    </tr>
    <tr>
        <td>Table cell B</td>
    </tr>
</table>

This moves Table cell B below Table cell A.

Tim S. Van Haren