Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

html - Irregularly spaced columns in a table

I am trying to create a table that's divided into to sections with 2 headings; one on top and one bottom. The top section will have 3 headings and 3 columns(<td>s). The second will have one long heading, 2 columns, and one long footer. I am having trouble getting the 2 bottom columns to span the length of the table (they are currently aligned with the first 2 columns on the upper section. enter image description here

I've tried using `colspan="1.5" (my logic is if the colspan="3", then half will work) as well as width="550px;" (the full width of the table is 1000px). Any suggestions here on what I do to achieve this? Code is below (Note: this is a javascript app that uses a DOM Node to dynamically create the table; I'm just using inline css to get it in there right now).

supplemental_dialog.innerHTML = "<h6>Map Date: " + this_date + "</h6>" + 
        "<div class='row' style='height:100px;'>" +
        "<div><h5>Location Information</h5>" +
        "<table id='table2' width=100%>" +
        "<tr width=100%>" +
        "<th><b>Flood Event</b></th>" + "<th><b>Estimated Flood Depth*</b></th>" + "<th><b>Estimated Base Flood Elevation*</b></th>" +
        "</tr>" +
        "<tr width=100%>" +
        "<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
        "</tr>" +
        "<tr width=100%>" +
        "<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
        "</tr>" +
        "<tr width=100%>" +
        "<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
        "</tr>" +
        "<tr width=100%>" +
        "<td width=33%>0.2 Percent (500 Year)</td><td width=33%>" + "14.5 feet above land surface" + "</td>" + "<td width=33%>" + "496.4 feet NAVD 1988" + "</td > " +
        "</tr>" +
        "<tr width=100%>" +
        "<th colspan='3' width=100% style='text-align:center'><b>Probability of Flooding </b></td>" +
        "</tr>" +
        "<tr width=100%>" +
        "<td width='500px'>0.2 Percent (500 Year)</td><td width='500px'>" + "14.5 feet above land surface" + "</td>" + 
        "</tr>" +
        "<tr width=100%>" +
        "<td width='500px'>0.2 Percent (500 Year)</td><td width='500px'>" + "14.5 feet above land surface" + "</td>" +
        "</tr>" +
        "<tr width=100%>" +
        "<td colspan='3' width=100%><p style='font-size: 10px;'>*The information included in this report is based on the entire building footprint, or, if clicked outside of a building footprint, based on the point clicked on the map.  Results are not considered an official determination.</p></td>" +
        "</tr>" +
        "</table></div > " +
        "</div>";  

To be clear; this is my goal: enter image description here

question from:https://stackoverflow.com/questions/65902623/irregularly-spaced-columns-in-a-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

one easy way here is by adding proper colspan values for different cells in different rows see the example :

<html>

<head>
  <style>
    table,
    th,
    td {
      border: 1px solid black;
    }
  </style>
</head>

<body>

  <table>
    <tr>
      <th colspan="2">first col</th>
      <th colspan="2">second col</th>
      <th colspan="2">third col</th>
    </tr>
    <tr>
      <td colspan="2">a</td>
      <td colspan="2">b</td>
      <td colspan="2">c</td>
    </tr>
    <tr>
      <td colspan="3">d</td>
      <td colspan="3">e</td>
    </tr>
    <tr>
      <td colspan="6">f</td>
    </tr>
  </table>

</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...