Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an HTML table inline

Tags:

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?

like image 684
oz1cz Avatar asked Sep 17 '11 19:09

oz1cz


People also ask

How do you inline a table style?

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 .)

How do you inline in HTML?

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.

What is inline table?

An inline table is a temporary table created using a VALUES clause.


2 Answers

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.

like image 159
Spadar Shut Avatar answered Nov 02 '22 06:11

Spadar Shut


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.

like image 35
Doctor Jonesington Avatar answered Nov 02 '22 06:11

Doctor Jonesington