Hi am trying to add a div above every <tr>
but when i look at the html console the div are showing outside the table. below is the html code.
<table> <div> <tr><td></td></tr> </div> <div> <tr><td></td></tr> </div> </table>
Is this not allowed? any help would be great.
If you use a div in a td you will however get in a situation where it might be hard to predict how the elements will be sized. The default for a div is to determine its width from its parent, and the default for a table cell is to determine its size depending on the size of its content.
Yes you can put table tag inside div tag .
<div>
tag can not be used above <tr>
tag. Instead you can use <tbody>
tag to do your work. If you are planning to give id
attribute to <div>
tag and doing some processing, same purpose you can achieve through <tbody>
tag. <div>
and <table>
are both block level elements. so they can not be nested. For further information visit this page
For example:
<table> <tbody class="green"> <tr> <td>Data</td> </tr> </tbody> <tbody class="blue"> <tr> <td>Data</td> </tr> </tbody> </table>
secondly, you can put "div" tag inside "td" tag.
<table> <tr> <td> <div></div> </td> </tr> </table>
Further questions are always welcome.
No, you cannot insert a div directly inside of a table. It is not correct html, and will result in unexpected output.
I would be happy to be more insightful, but you haven't said what you are attempting, so I can't really offer an alternative.
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