Making a table with subColumn in HTML

Viewed 112

I have been trying to make table with 4 columns and 2 sub columns in HTML but my every attempt has failed didn't event went close to what I wanted to do,

here is a snap of what I am trying to make:

Table Image

3 Answers

What you need is colspan. It will tell the cell it should occupy more columns.

<table>
  <tr>
    <th>Header</th>
    <th>Header</th>
    <th colspan="2">Header</th>
    <th>Header</th>
  </tr>
  <tr>
    <th>Header</th>
    <th>Header</th>
    <th>Header</th>
    <th>Header</th>
    <th>Header</th>
  </tr>
  <tr>
    <td>Content</td>
    <td>Content</td>
    <td>Content</td>
    <td>Content</td>
    <td>Content</td>
  </tr>
</table>

See demo here https://codepen.io/korinektomas/pen/XWegrmz

Here is My Solution, I used colspan attribute

Learn More About colspan

<table border="1">
  <tr>
    <th>SL.No</th>
    <th>Number of Oxalic acid in ML</th>
    <th colspan="2">Burette readings</th>
    <th>Valume (V) of KMnO<sub>4</sub> Used V=(y-x) mL</th>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>initial (x)</th>
    <th>Final(y)</th>
    <th>&nbsp;</th>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

html,
body {
  width: 100%;
}

table {
  margin: 0 auto;
}

table {
  width: 80%;
  border-collapse: separate;
  border: solid black 1px;
  border-radius: 6px;
}

thead {  background-color: #FFE4C4 }

tr {
  font-family: 'Times New Roman', Times, serif;
  text-align: center;
}

td, th {   border: 1px solid black; }

h3 {
  text-align: center;
}
<h3> Table 6.1 : Titration of potassium permanganatc solution against standard oxalic solution </h3>


<table>
<thead>
  <tr>
    <th> SI.NO</th>
    <th> Volume of Oxaic acid in ML </th>
    <th colspan="2"> Burette readings </th>
    <th> Valume (V) of KMnO<sub>4</sub> Used V=(y-x) mL</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td></td>
    <td></td>
    <td style="width: 100px;">
      <h4>initial (x)</h4>
    </td>
    <td style="width: 100px;">
      <h4>Final(y)</h4>
    </td>
    <td></td>
  </tr>

  <tr>
    <td>
      <pre> </pre>
    </td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>

  <tr>
    <td>
      <pre> </pre>
    </td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</tbody>
</table>

Related