Rumah > Artikel > hujung hadapan web > HTML Colspan
HTML Colspan ialah atribut yang digunakan dalam jadual untuk menyelam lajur ke dalam sel. Ia membolehkan pengguna membahagikan sel jadual tunggal ke dalam lebar satu atau lebih sama ada sel atau lajur. Atribut HTML ini berfungsi sebagai pilihan sel gabungan yang disertakan dalam hamparan, sama seperti excel. Atribut ini digunakan untuk menerangkan bilangan sebenar lajur dibahagikan dengan lajur individu.
atribut jadual colspan digunakan dalam kedua-dua elemen jadual seperti
atribut colspan dalam HTML boleh digunakan seperti berikut:
Sintaks:
<td colspan="value">table content…</td>
Sintaks:
<th colspan="value">table content…</th>
Sintaks:
<ElementName cols="value">……………….</ElementName>
Pelaksanaan kod colspan dalam HTML diterangkan di bawah.
Kod:
<!DOCTYPE html> <html> <head> <title>HTML colspan Attribute with <td> tag</title> <style> table, th, td { border: 2 px solid blue; border-collapse: collapse; padding: 5px; text-align:left; } </style> </head> <body> <center> <h1 style="color: blue;">State With it’s capital </h1> <h2>HTML colspan Attribute</h2> <table> <tr> <th>State </th> <th>Capital </th> </tr> <tr> <td>Andhra Pradesh</td> <td>Hyderabad</td> </tr> <tr> <td>Bihar </td> <td>Patna</td> </tr> <tr> <td>Goa </td> <td>Panaji</td> </tr> <tr> <td>Maharashtra </td> <td>Mumbai </td> </tr> <tr> <td>Nagaland</td> <td>Kohima </td> </tr> <tr> <td>Punjab </td> <td>Chandigarh </td> </tr> <tr> <td> Gujarat</td> <td> Gandhinagar</td> </tr> <tr> <td>Haryana </td> <td>Chandigarh </td> </tr> <tr> <td colspan="2">India</td> </tr> </table> </center> </body> </html>
Output:
Kod:
<!DOCTYPE html> <html> <head> <title>HTML colspan Attribute</title> <style> table, th, td { border: 3px solid red; border-collapse: collapse; } </style> </head> <body> <center> <h1 style="color: grey;">Population</h1> <h2>HTML colspan Attribute with <th> tag</h2> <table> <tr> <th colspan="2">Gender</th> </tr> <tr> <td>Male</td> <td>18</td> </tr> <tr> <td>Female</td> <td>24</td> </tr> </table> </center> </body> </html>
Output:
Berikut ialah contoh yang berbeza.
Status contoh ini yang akan digunakan oleh atribut colspan dengan pengepala jadual bersama-sama dengan
Kod HTML:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 2px solid blue; border-collapse: collapse; padding:5px; } </style> </head> <body> <table> <h1 style="text-align: center;">Employee Details</h1> <tr> <th colspan="1"></th> <th colspan="2">Software</th> <th colspan="2">Hardware</th> <th colspan="2">Marketing</th> <th colspan="2">HR</th> <th colspan="3">Others</th> </tr> <tr> <th >Department</th> <th>.NET</th> <th>JAVA</th> <th>Embedded</th> <th>Mechanical</th> <th>Indoor</th> <th>Outdoor</th> <th>Onside</th> <th>Offside</th> <th>Accounts</th> <th>Assets</th> <th>Canteen</th> </tr> <tr> <td>Head Person</td> <td>John</td> <td>Disuja</td> <td>Kartik</td> <td>Gary</td> <td>Sreja</td> <td>Divya</td> <td>Sandesh</td> <td>Krutika</td> <td>P. Roy</td> <td>Mohan</td> <td>Joggy</td> </tr> <tr> <td>Experience(in years)</td> <td>17</td> <td>12</td> <td>8</td> <td>7</td> <td>12</td> <td>11</td> <td>5</td> <td>9</td> <td>7</td> <td>12</td> <td>5</td> </tr> <tr> <td>No of Teams</td> <td>5</td> <td>5</td> <td>7</td> <td>7</td> <td>3</td> <td>2</td> <td>2</td> <td>2</td> <td>5</td> <td>5</td> <td>5</td> </tr> <tr> <td>Assigned Projects/Task</td> <td>18</td> <td>15</td> <td>7</td> <td>11</td> <td>5</td> <td>5</td> <td>2</td> <td>2</td> <td>4</td> <td>10</td> <td>6</td> </tr> <tr> <td>No of employees</td> <td>182</td> <td>150</td> <td>75</td> <td>82</td> <td>34</td> <td>25</td> <td>2</td> <td>5</td> <td>4</td> <td>10</td> <td>6</td> </tr> <tr> <td>Weekly standup</td> <td>Monday</td> <td>Monday</td> <td>Friday</td> <td>Friday</td> <td>Tuseday</td> <td>Tuseday</td> <td>Everyday</td> <td>Everyday</td> <td>Friday</td> <td>Friday</td> <td>Friday</td> </tr> <tr> <td>Appriasal Month</td> <td>March</td> <td>March</td> <td>March</td> <td>March</td> <td>June</td> <td>June</td> <td>March</td> <td>March</td> <td>June</td> <td>June</td> <td>June</td> </tr> </table> </body> </html>
Output:
Dalam contoh ini, kami akan menerangkan cara lajur boleh dibahagikan menggunakan tag colspan dan apakah output sebenar dengan menggunakan tag colspan akan dijana seperti berikut:
Kod HTML:
<!DOCTYPE html> <html> <head> <title>HTML colspan Attribute</title> <style> table, th, td { border: 1px solid black; border-collapse: collapse; padding:8px; } </style> </head> <body> <center> <h1 style="color: greenyellow;">Weather in India</h1> <table> <tr> <th> Temperature (in degree Celsius)</th> </tr> <tr> <td >Agartala</td> <td >17</td> </tr> <tr> <td>Amritsar</td> <td>23</td> </tr> <tr> <td>Aurangabad</td> <td>26</td> </tr> <tr> <td>Bangalore</td> <td>23</td> </tr> <tr> <td>Bhopal</td> <td>13</td> </tr> <tr> <td>Chennai</td> <td>25</td> </tr> <tr> <td>Delhi</td> <td>11</td> </tr> <tr> <td>Haridwar</td> <td>8</td> </tr> <tr> <td>Hubbali</td> <td>25</td> </tr> <tr> <td>Indore</td> <td>15</td> </tr> <tr> <td>Kanyakumari</td> <td>28</td> </tr> <tr> <td>Katra</td> <td>8</td> </tr> <tr> <td>Mumbai</td> <td>26</td> </tr> <tr> <td colspan="2"><b>Average Temperature = 19.07</b></td> </tr> </table> </center> </body> </html>
Output:
Dalam contoh ini kita akan menggunakan tag HTML colspan dalam kedua-dua
Kod HTML:
<!DOCTYPE html> <html> <head> <title>HTML colspan Attribute</title> <style> table, th, td { border: 2px solid black; border-collapse: collapse; padding:8px; } </style> </head> <body> <center> <h1 style="color:deepskyblue;">Pune Highlights</h1> <table> <tr> <th colspan="2"> Famous Area in Pune</th> </tr> <tr> <td colspan="1">Koregaon Park</td> <td >Kalyani nagar</td> </tr> <tr> <td colspan="1">PMC</td> <td >PCMC</td> </tr> <tr> <td colspan="2">Kothrud</td> </tr> <tr> <td colspan="2">Chakan</td> </tr> <tr> <td colspan="1">Vishrantwadi</td> <td >Lohgaon</td> </tr> <tr> <td colspan="1">Hadpsar</td> <td >Swargate</td> </tr> <tr> <td colspan="1">Decan</td> <td >Baner</td> </tr> <tr> <td colspan="1">Bavdhan</td> <td >Wakad</td> </tr> <tr> <td colspan="1">Pimpri Chinchwad</td> <td >Akurdi</td> </tr> <tr> <td colspan="2" >Vimannagar </td> </tr> <tr> <td colspan="1">Wagholi</td> <td >Katraj</td> </tr> <tr> <td colspan="1">Hinjewadi</td> <td >Khadkwasla</td> </tr> <tr> <td colspan="1">Camp</td> <td >Laxmi Road</td> </tr> </table> </center> </body> </html>
Output:
Atas ialah kandungan terperinci HTML Colspan. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!