I’m new to HTML and would like to create a table that looks like the one in this picture:
I have a close attempt, but some columns in the middle are merged unlike the table shown in the bottom of the picture. I want my code to have split columns like in that bottom table.
<h6>↓ My Table ↓</h6>
<table border="3">
<tr align="center">
<th colspan="7">Element</th>
</tr>
<tr>
<th>I</th>
<th>II</th>
<th>III IV V</th>
<th>VI</th>
<th>VII</th>
</tr>
<tr>
<td>H</td>
<td> </td>
<td rowspan="3">Periyodik Element<br><center>Tablosu</center></td>
<td>` `</td>
<td>He</td>
</tr>
<tr>
<td>Li</td>
<td>Be</td>
<td>B</td>
<td>Ne</td>
</tr>
<tr>
<td>Ne</td>
<td>Mg</td>
<td>Al</td>
<td>Ar</td>
</tr>
<tr>
<td>K</td>
<td>Ca</td>
<td><center>Sc Ti V</center></td>
<td>Ga</td>
<td>Kr</td>
</tr>
</table>
2
Answers
Solution
The setting you are looking for is the
colspan
attribute.In
colspan
, you can specify how many columns wide a particular column should be. For example, in the cell with the text "Periodic Table of Elements", where you have correctly set therowspan
to be 3 rows high, you should also set thecolspan
to be 3 columns wide.Any cell that spans multiple columns in the image should be represented by multiple separate cells in the code. So, instead of entering the "III, IV, and V" cells in one cell, you should enter them in three different cells. Please follow my example to understand the solution.
More information
<td>
colspan attribute – MDNUse CSS for formatting (ex.
text-align: center;
ordisplay: block;
orfont-weight: bold;
) instead of HTML elements (ex.<center>
,<br>
,<strong>
, etc.)What’s CSS?
Use
class
for CSS formatting – MDNThe borders are a bit tricky but
colspan
was required on your rowspan table cell.