How do I make an HTML table inline

前端 未结 5 913
猫巷女王i
猫巷女王i 2021-01-03 21:49

In HTML I want to display a small table as part of a paragraph. One way to do that is this:

Before <
相关标签:
5条回答
  • 2021-01-03 22:00

    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.

    0 讨论(0)
  • 2021-01-03 22:09

    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.

    0 讨论(0)
  • 2021-01-03 22:11

    it doesn't work because <table> shouldn't be a child of <p>

    (you can try the W3C validator to see more about this error)

    simply replace <p> with <div>

    0 讨论(0)
  • 2021-01-03 22:12

    Making the paragraph display: inline; works for me. But, if you have multiple paragraphs, you will have to add a <br /> after each of them.

    0 讨论(0)
  • 2021-01-03 22:16

    I suppose that you have a good reason to use a table here instead of css. You can get the effect using a single table.

    <table>
      <tr>
        <td rowspan="2">Before</td>
        <td>a</td>
        <td>b</td>
        <td rowspan="2">After</td>
      </tr>
      <tr>
        <td>c</td>
        <td>d</td>
      </tr>
    </table>
    
    0 讨论(0)
提交回复
热议问题