Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we add div inside table above every <tr>?

Tags:

html

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.

like image 246
Amit Avatar asked May 03 '14 04:05

Amit


People also ask

Can I use div in TD?

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.

Can a table go inside a div?

Yes you can put table tag inside div tag .


2 Answers

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

like image 55
Aditya Ekbote Avatar answered Sep 28 '22 18:09

Aditya Ekbote


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.

like image 22
Patrick Avatar answered Sep 28 '22 17:09

Patrick