HTML Table – Colspan & Rowspan
📘 HTML Table – Colspan & Rowspan Explained in Hindi
HTML Tables में कभी-कभी ज़रूरत होती है कि एक cell एक से अधिक columns या rows में फैले। इसके लिए HTML हमें दो attributes देता है:
colspan
→ column में फैलाने के लिएrowspan
→ row में फैलाने के लिए
इस chapter में हम इन दोनों का प्रयोग करके merged cells, complex headers, और advanced layouts बनाना सीखेंगे।
🔷 1. colspan – एक cell को कई कॉलम में फैलाना
जब आप चाहते हैं कि एक cell दो या अधिक कॉलम की जगह ले ले, तो colspan
का उपयोग करें।
✅ Example:
<table border="1">
<tr>
<th colspan="2">विद्यार्थी की जानकारी</th>
</tr>
<tr>
<td>नाम</td>
<td>राम</td>
</tr>
</table>
📌 यहाँ पहली row का cell दो कॉलम को cover कर रहा है।
🔷 2. rowspan – एक cell को कई rows में फैलाना
जब आप चाहते हैं कि एक cell ऊपर-नीचे की दो या अधिक rows को जोड़ दे, तो rowspan
का उपयोग करें।
✅ Example:
<table border="1">
<tr>
<th rowspan="2">दिन</th>
<th>सुबह</th>
</tr>
<tr>
<td>योग</td>
</tr>
</table>
📌 “दिन” वाला cell दो rows में फैला है।
🔷 3. Combined Example – Colspan और Rowspan साथ में
<table border="1">
<tr>
<th rowspan="2">दिन</th>
<th colspan="2">समय</th>
</tr>
<tr>
<th>सुबह</th>
<th>शाम</th>
</tr>
<tr>
<td>सोमवार</td>
<td>योग</td>
<td>पढ़ाई</td>
</tr>
</table>
📌 इस table में:
- “दिन” rowspan से दो rows में फैला है
- “समय” colspan से दो कॉलम को कवर कर रहा है
🔷 4. colspan और rowspan कब उपयोग करें?
स्थिति | क्या करें |
---|---|
Header को merge करना है | colspan |
एक ही data को multiple rows के लिए दिखाना है | rowspan |
Weekly Schedule या Report card बनाना है | दोनों का प्रयोग करें |
🔷 5. CSS Styling के साथ प्रयोग
<style>
th {
background-color: #f2f2f2;
text-align: center;
padding: 10px;
}
td {
text-align: center;
padding: 8px;
}
</style>
🧪 Practice Task
- एक table बनाइए जिसमें “Course Info” नाम का cell दो columns को कवर करे।
- एक table बनाइए जिसमें “दिन” cell दो rows को कवर करे।
- एक table बनाइए जो timetable की तरह structured हो और उसमें rowspan और colspan दोनों का प्रयोग हो।
❗ ध्यान रखें:
गलती | समाधान |
---|---|
Extra cells error आ रही है | colspan या rowspan से cell count सही manage करें |
Borders mismatch हो रहे हैं | table को grid layout में पहले draw करें, फिर cells assign करें |
Text align गड़बड़ है | text-align , padding , vertical-align CSS से सुधारें |
🔚 Conclusion
colspan
औरrowspan
HTML tables में cells को merge करने के लिए बहुत उपयोगी हैं।- Complex layouts, headers और reports के लिए ये ज़रूरी होते हैं।
- सही प्रयोग के लिए cell की total count को balance करना जरूरी है।