Question
Can the colspan
attribute only be used within <td>
tags?
Answer
No. The colspan
attribute can also be used on <th>
tags. For improved accessibility, when we create table headings that span multiple columns, we should also include the scope=”colgroup”
attribute within the opening <th>
tag.
19 Likes
Could I create each colspan for each column?
1 Like
Hi,
since each “th” tag forms a column,
I think you meant to ask this question:
can every “th” tag have a colspan attribute?
The answer is YES because I’ve just tried it now
and here’s the screenshots :
note: I didn’t give Tuesday and Thursday an colspan attribute and I added an empty table cell “td” for them, I mean that you have to put in mind how much “td” tags you’ve got.
hope that helps
16 Likes
I guess you are trying to do this…
The output will be
11 Likes
“SCOPE” attribute isn’t it used just for “th” ?? Don’t think we can apply it for “td”!
1 Like
Literally see the 2 comments above…
Although you CAN use scope for , I think it is considered bad form, or even wrong. The MDN even seems to imply this.
This enumerated attribute defines the cells that the header (defined in the [ <th>
] element relates to.
No I don’t think so. Its not possible to span several columns for each column. It won’t make any sense. If you are trying to say that you wish to copy a column for several times, then you should write everything twice. Its something like this:
<th scope="col" > Company Name</th>
<th scope="col" > Company Name</th>
<td colspan="2">Adam's Greenworks</td>
<td colspan="2">Davie's Burgers</td>
.
.
.
So in screen you can see that both Company Name headings have same data. Like this:
If you asking for each header, than yes you can. so if you want company name and next action to span across 2 columns than yes you can. You would need to insert the colspan attribute for company name and next action and assign the value to 2.
New to coding. I was flying through the program and for some reason I’ve hit a roadblock. Can someone help me out on this part.
You should add the colspan attribute to one of the td
elements.
Spanning two columns would be colspan="2"
.
I did that for a td
element in a row close to the end of the table.
<tr>
<td>Shane's Bistro</td>
<td colspan="2">unavailable</td>
</tr>
Here i got stuck too…help:d