omg
omg

Reputation: 139862

why TDs display within a TR displays in the same line?

TD is a block element,

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

why?

Upvotes: 2

Views: 660

Answers (5)

Timothy S. Van Haren
Timothy S. Van Haren

Reputation: 8966

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.

Upvotes: 0

Matt Bridges
Matt Bridges

Reputation: 49385

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.

Upvotes: 14

Gab Royer
Gab Royer

Reputation: 9806

Because, that's how tables work.

Upvotes: 1

David M
David M

Reputation: 72860

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

Upvotes: 0

Sampson
Sampson

Reputation: 268344

Because they are for tabular data.

Upvotes: 1

Related Questions