skip to Main Content

I am creating a marksheet design using an HTML table.
I have this design
enter image description here

and what I created
enter image description here

As you can see in the third column of the first row secured, pass, and total there are three columns, I have created a table for these three columns but not getting exact and getting issues with width and border touch with the below row columns.
My HTML code

   <table border="0" width="100" class="table4 table3" style="border-left: 3px solid #fff;border-right: 3px solid #fff;">
      <tr>
        <td style="width:60px;" class="text-center">Sr. <br> No.</td><td class="text-center" style="width:800px !important;">Paper Nomenclature</td>
        
        <td class="text-center" colspan="3" style="width:220px !important;">Marks
<table style="width: 100%;border-left: 3px solid #fff;border-right: 3px solid #fff; margin-left: -10px;border-bottom: 3px solid #fff;" class="">
  <tr>
    <td>Secured</td> <td>Pass</td> <td>Total</td>
  </tr>
</table>
        </td> 
</table>

 <tr>
        <td style="width:60px;" class="text-center">2 .</td>
        <td>
          <table border="0" style="width:100%; border: 0px !important; border-color: #fff !important;" class="table5">
            <tr>
              <td>Punjabi (Compulsory )</td>
               <td style="width:350px;">
                               <table border="1" style="width:100%;border:0px !important;margin-top: -25px; height:40px;"></table>
                            <table border="1" style="width:100%;border:0px !important;margin-top: -15px;">
                  <tr> 
                    <td> 45</td><td> 31</td><td> 45</td><td> 45</td> <td> 55</td> 
                  </tr>
                </table>
               </td>
            </tr>
          </table>
        </td>
        <td class="text-center">
          221        </td> <td class="text-center">35</td> <td class="text-center">100</td> 
      </tr>
 

Am I doing something wrong?
Secured, pass, the total column should be stretched according to the below columns and fit to width,

2

Answers


  1. You can also use the rowspan attribute to merge some rows in HTML. The rowspan attribute specifies how many rows a cell should span across. For example, if you want to merge the first two rows in the first column, you can write something like this:

    <table>
      <tr>
       <td rowspan="2">Merged cell</td>
       <td>Cell 2</td>
       <td>Cell 3</td>
       <td>Cell 4</td>
      </tr>
      <tr>
       <td>Cell 6</td>
       <td>Cell 7</td>
       <td>Cell 8</td>
      </tr>
      <tr>
        <td>Cell 9</td>
        <td>Cell 10</td>
        <td>Cell 11</td>
        <td>Cell 12</td>
      </tr>
    </table>
    

    The result will look like this screenshot:
    enter image description here

    Furthermore, You can combine the colspan and rowspan attributes to merge cells in both directions.

    Login or Signup to reply.
  2. You can merge cells and achieve the same using rowspan and colspan rather than using a nested tables

    table {
        border-collapse: collapse;
    }
    
    tbody td, tbody th {
        border: 1px dashed #595959;
        padding: 3px;
        width: 30px;
        height: 25px;
    }
    
    tbody td:first-child,
    tbody th:first-child {
        border-left: none; /* Remove left border for first column */
    }
    
    tbody td:last-child,
    tbody th:last-child {
        border-right: none; /* Remove right border for last column */
    }
    <table style="width:100%">
        <tbody>
            <tr>
                <td rowspan="2" style="text-align:center">Sr. No.</td>
                <td rowspan="2" style="text-align:center">Paper Nomenclature</td>
                <td colspan="3" style="text-align:center">MARKS</td>
            </tr>
            <tr>
                <td style="text-align:center">Secured</td>
                <td style="text-align:center">Pass</td>
                <td style="text-align:center">Total</td>
            </tr>
            <tr>
                <td>...</td>
                <td>...</td>
                <td>...</td>
                <td>...</td>
                <td>...</td>
            </tr>
        </tbody>
    </table>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search