HTML Colspan & Rowspan
In this page:
<td colspan="number">Spans columns</td>
<td rowspan="number">Spans rows</td>
colspan से Columns को Span करना
किसी <td> या <th> पर colspan="2" उस single cell को दो साधारण columns जितनी जगह में फैला देता है, जिसका मतलब है कि उसे रखने वाली row में table की बाकी rows की तुलना में grid alignment बनाए रखने के लिए एक cell कम होनी चाहिए।
यह किसी table में full-width section title row बनाने की standard technique है।
- जब कोई cell colspan="3" उपयोग करे, तो उसी row में उसके बाद आने वाली दो normal cells हटा दें।
- Accepted values:
- colspan — positive integer (default 1)
- td और th पर valid
उदाहरण: Spanning Columns with colspan
<table>
<tr>
<td colspan="2">Full width title</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
</tr>
</table>
rowspan से Rows को Span करना
किसी <td> या <th> पर rowspan="2" उस single cell को vertically दो rows जितनी जगह में फैला देता है, जिसका मतलब है कि जिन rows में यह फैलता है उनमें से हर एक में एक cell कम होनी चाहिए, क्योंकि वह column position पहले से ऊपर की spanning cell से भरी हुई है।
- जब कोई cell rowspan="3" उपयोग करे, तो अगली दो rows से पूरी तरह वही column position हटा दें।
- Accepted values:
- rowspan — non-negative integer (default 1)
- 0 row group के अंत तक फैलता है
उदाहरण: Spanning Rows with rowspan
<table>
<tr>
<td rowspan="2">Spans two rows</td>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
</tr>
</table>
colspan और rowspan को साथ Combine करना
कोई single cell colspan और rowspan को साथ उपयोग कर सकती है, जो एक साथ कई columns और कई rows के एक rectangular block में फैलती है -- यह किसी matrix-style table में corner label cell के लिए उपयोगी है जहां उसे एक से ज़्यादा row और column पर कब्जा करना हो।
- दोनों attributes को combine करते समय पहले कागज़ पर intended grid स्केच करें, क्योंकि यह track करना कि exactly कौन सी cells consume हो रही हैं जल्दी complex हो जाता है।
- Accepted attributes:
- colspan — positive integer
- rowspan — non-negative integer
उदाहरण: Combining colspan and rowspan
<table>
<tr>
<td rowspan="2" colspan="2">Corner label</td>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
</table>
एक Complex Schedule Table बनाना
colspan और rowspan मिलकर बिल्कुल वही संभव बनाते हैं जो weekly class schedule जैसी आम असल-दुनिया की tables को possible बनाता है, जहां एक single multi-hour class block कई time-row slots में फैलता है, या एक merged header पूरे दिन के column में फैलता है।
उदाहरण: Building a Complex Schedule Table
<table>
<tr>
<th>Time</th>
<th colspan="2">Monday</th>
</tr>
<tr>
<td>9am</td>
<td rowspan="2">Math Class</td>
</tr>
</table>
Spanned Cells के लिए Accessibility Considerations
Spanned cells screen reader users को confuse कर सकती हैं अगर reading order स्पष्ट न हो, क्योंकि एक merged cell simple one-cell-per-row-per-column वाली assumption को तोड़ देती है।
scope जोड़ना, और complex मामलों के लिए headers/id association technique, assistive technology को सही ढंग से यह announce करने में मदद करता है कि कौन सा spanned header किस data cell पर लागू होता है।
उदाहरण: Accessibility Considerations for Spanned Cells
<table>
<tr>
<th id="monday" scope="col">Monday</th>
</tr>
<tr>
<td headers="monday">Math Class</td>
</tr>
</table>
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists