HTML Cell Alignment with nested Table

Eduardo Aviles
Eduardo Aviles used Ask the Experts™
on
Hello Experts, I am hoping you can help with my dilemma. I have an HTML page that has two tables one table nested to the other. What I need to do is align the cell width of the second table to match with the first one. I have tried everything to get it to work with no success. Any help would be most appreciated.

Code:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=10">
  <meta name="viewport" content="width=device-width, initial-scale=1">

<style>
      /* Create two equal columns that floats next to each other */
      .middle {
            
            width: 900px;
            padding: 10px;
            border: solid;
            margin-left: auto;
            margin-right: auto;

      }
</style>
</head>
<body  bgcolor = "#86888c" text="Black">
 <div class="middle" style="background-color:#3399ff;" >
    <p>
      
            <b><center><font size="3">
            Testing <br>
            Request<br>
            <font size="2" color = "Red">Version 5.0 - Development</font>
            </center></b></font>

      </p>
      <table  border="1"  id="content"  style="width:100%" >
      
            <tr>
                  <td style="padding-left: 10px" style="font-size: 12pt">Number:</td>
                  
                  <td style="padding-left: 10px" style="font-size: 12pt">
                  
                  <input type="text" style="width:150px;" name = "RequestNum" size="20" title="" id="RequestNum" disabled/><i><font size="2">
                  </td>
                  
                  <td style="padding-left: 10px" style="font-size: 12pt">Title:</td>
                  
                  <td><input type="text" style="width:200px;"  id="DocTitle" name = "DocTitle" title="" color="black" rows="2" cols="50" maxlength="30" style="width:150px;">
                  </td>
            </tr>

            
            <tr>
                  <td style="padding-left: 10px" style="font-size: 12pt">Doc Number:</td>
                  <td style="padding-left: 10px" style="font-size: 12pt"><input type="text" class="doc" style="width:150px;" id="docNum0"/></td>
      
                  <td style="padding-left: 10px" style="font-size: 12pt" >Doc Rev: </td>
                  <td><input type="text" class="rev" style="width:40px;" id="rev0"> <input type="button" id="more_fields" onclick="add_fields();" value="+" /></td>
            </tr>
                  

      </table>
      <table border="1" style="width:100%">
      
            <tr>
                  <td style="padding-left: 10px">Program:</td>
                  <td style="padding-left: 10px">
                        <Select name="Program" title="" style="width:150px;" id="Program">
                        <option value="" selected>- Select -</option>
                        <option value="Test1">Stress</option>
                        <option value="Test2">Test</option>
                        </Select>
                  </td>
                  
                  <td style="padding-left: 10px">Creation Date:</td>
                  <td>
                        <input type ="CrDateCalc" name= "CrDateCalc" id="CrDateCalc" size="20" style="width:150px;" title="" readonly/>
                  </td>
            </tr>
            <tr>
                  <td colspan="100%">
                        <hr></hr>
                  </td>
            </tr>
      
            <tr>            
                  <td colspan="2" style="font-size: 12pt"/>Testing Together:
                  
                        <Select id="" name="" title="">
                              <option value="No">No</option>
                              <option value="Yes">Yes</option>
                        </Select>
                  </td>
            </tr>
            <tr>
            </tr>
</body>
</div>
</html>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Web Developer/Designer
Commented:
Table columns (TD) adjust to the width of the contents. If you need them to be a set width then the width needs to be defined explicitly.
https://www.w3schools.com/tags/att_td_width.asp (can be done with css, doesn't need to be inline)
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
Hi Eduardo,

Basically, it's not a good idea to it this way.

Else you need to set the same width for the TD's of both tables using classes or direct style, IMO using the percent % width will be more efficient in this case.

Working live fiddle
Hi,

First don't place a form in table this is not a good practice, use DIV instead.
Also don't use inline CSS this is not a good practice, use external .css file with class.

You will see this is simpler to work and adapt the CSS and you will have uptodate code (not old fashion)...
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
First don't place a form in table this is not a good practice, use DIV instead

A form is not allowed to be a child element of a table or tbody or tr.

In fact, I can't see any form inside the posted HTML, the current structure is valid and if the author wants a form then he can use it around the entire table that will not affect the correctness of the code.

You can have an entire table inside a form and you can have a form inside a table cell but you cannot have part of a table inside a form.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial