In HTML I want to display a small table as part of a paragraph. One way to do that is this:
<table>
<tr>
<td>
Before
<table style="display:inline;"><tr><td>a</td><td>b</td></tr> <tr><td>c</td><td>d</td></tr> </table>
After
</td>
</tr>
</table>
which produces this nice layout:
a b
Before After
c d
which is exactly what I want.
But it seems rather silly to me to use a table inside a table when what I really want is to use a table inside a paragraph. However, if I try using this HTML:
<p>
Before
<table style="display:inline;"><tr><td>a</td><td>b</td></tr> <tr><td>c</td><td>d</td></tr></table>
After
</p>
I get this ugly layout:
Before
a b
After
c d
I've tried using various different display styles, but none seem to do what I want.
Am I forced to use the table-within-table code, or am I missing something?
Inline styles are created by adding the style attribute to a tag. As with the class and id attributes, almost all elements can take the style attribute. (Exceptions include html , head , title , meta , script , and style .)
The <span> element is an inline container used to mark up a part of a text, or a part of a document. The <span> element has no required attributes, but style , class and id are common.
An inline table is a temporary table created using a VALUES clause.
You could use the following css:
display:inline-table
onnly IE7 and below don't support this property. Probably wrapping the table in a span with zoom:1
applied to it could help IE7.
I'm using Chrome browser on Linux and I am able to get this to work by adding display:inline-table
to both the paragraph (p) and table tags:
<p style="display:inline-table;">
Before
<table style="display:inline-table;"><tr><td>a</td><td>b</td></tr> <tr><td>c</td><td>d</td></tr></table>
After
</p>
Just checked Firefox on Linux and it seems to work there too.
FYI: Removing either of the two display:inline-table
styles gave undesirable formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With