-1

I would like to style paragraphs and table contents in the same way.

p, table {
    color:#555;
    font-family:Arial;
}

But when a table is inserted inside a paragraph

<p>Some text
<table>
    <tr><td>Text inside table</td></tr>
    <tr><td>Text inside table</td></tr>
</table>
Some other text    
</p>

Fiddle

the text following the table (Some other text) doesn't have the desired style.
Does table break paragraph style?

Giorgio
  • 1,940
  • 5
  • 39
  • 64
  • You might be able to find your answer here: http://stackoverflow.com/questions/1944213/is-it-good-to-put-p-inside-td-to-put-content-text – Master Yoda Jan 20 '15 at 10:23
  • You can't put `` inside `

    `. Check [http://stackoverflow.com/questions/7459652/table-tag-not-nesting-inside-p-tags-in-dom](http://stackoverflow.com/questions/7459652/table-tag-not-nesting-inside-p-tags-in-dom)

    – Prachit Jan 20 '15 at 10:25

1 Answers1

3

HTML does not allow a paragraph to contain a table.

The end tag for a paragraph is optional.

Starting a table implicitly terminates the paragraph and the table is a sibling of the paragraph and not a child of it.

The text node following the table is also a child node of the paragraph's parent element.

The end tag for the paragraph is ignored since it is an error.

You would have noticed this if you had inspected the DOM using your browser's developer tools or validated your HTML.

This is how it is rendered:

 <p>Some text </p>
 <table>
    <tbody>
     <tr>
       <td>Text inside table</td>
     </tr>
     <tr>
      <td>Text inside table</td>
     </tr>
    </tbody>
</table>Some other text 
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335