为什么我的表格中的最后 3 行单元格没有与 HTML 表格中的第一行完美对齐?

发布于 2024-09-14 12:20:26 字数 564 浏览 2 评论 0原文

这是链接我的表格行未对齐的示例

单击左上角的预览JS Bin 菜单栏可以看到这个示例的工作原理。您可以看到带有电子邮件输入字段的表格单元格的顶部 2 个边框比左侧 2 个表格单元格的顶部 2 个边框稍低其中(用户名输入字段)。

为什么会发生这种情况?

另外我发现我必须在第二个元素中为 元素编写 rowspan="4"让它们跨越旁边的 3 行。为什么我必须这样做?如果我只需要清除 3 行,那就没有意义了。就好像某处隐藏着一个神秘的行。

更新示例答案:

我在这个示例中实现了答案。 如您所见,有所有表格单元格之间完美对齐。

Here is a link my example of the misaligned table rows

Click preview in the upper top left corner of the JS Bin menu bar to see this example in the works. You can see the top 2 borders of the table cells with Email and an input field in them are a bit lower than the top 2 borders of the 2 table cells to the left of them (Username and an input field).

Why is this happening?

Also I am finding I have to write rowspan="4" for <th> and <td> elements in the second element to make them span the 3 rows beside it. Why do I have to do that? It makes no sense if there are only 3 rows I have to clear. It's as if there is a mysterious hidden row somewhere.

UPDATE with example answer:

I implemented the answer in this example. As you can see, there is perfect alignment between all table cells.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方。的韩爷 2024-09-21 12:20:26

对...简单...

基本上,第二行需要有 4 个单元格,用户名和输入单元格以及电子邮件和输入单元格...

用户名和输入单元格需要有 rowspan=" 3" 然后接下来的两行需要是密码和新密码及其输入字段。

代码:

<html>
  <head>
  </head>
  <body>
    <table border="1">
      <tbody>
        <tr>
          <th colspan="4" rowspan="1">
            <h3>Profile Settings</h3>
          </th>
        </tr>
        <tr>
          <th rowspan="3">
            <label for="">USERNAME:</label>
          </th>
          <td rowspan="3">  
            <input type="text">
          </td>
          <th>
            <label for="">Email:</label>
          </th>
          <td>  
            <input type="text">
          </td>  
        </tr>
        <tr>
          <th>
            <label for="">Password:</label>
          </th>
          <td>  
            <input type="password">
          </td>  
        </tr>  
        <tr>
          <th>
            <label for="">New Password:</label>
          </th>
          <td>  
            <input type="password">
          </td>  
        </tr>
        <tr>
          <td colspan="4">  
            <input type="button" value="save">
          </td>  
        </tr>
      </tbody>
    </table>
  </body>
</html>

right... easy peasy...

basically, the second row needs to have 4 cells in it, the username and input cells AND the email and input cells...

the username and input cells need to have rowspan="3" and then the NEXT two rows need to be password and new password with their input fields.

code:

<html>
  <head>
  </head>
  <body>
    <table border="1">
      <tbody>
        <tr>
          <th colspan="4" rowspan="1">
            <h3>Profile Settings</h3>
          </th>
        </tr>
        <tr>
          <th rowspan="3">
            <label for="">USERNAME:</label>
          </th>
          <td rowspan="3">  
            <input type="text">
          </td>
          <th>
            <label for="">Email:</label>
          </th>
          <td>  
            <input type="text">
          </td>  
        </tr>
        <tr>
          <th>
            <label for="">Password:</label>
          </th>
          <td>  
            <input type="password">
          </td>  
        </tr>  
        <tr>
          <th>
            <label for="">New Password:</label>
          </th>
          <td>  
            <input type="password">
          </td>  
        </tr>
        <tr>
          <td colspan="4">  
            <input type="button" value="save">
          </td>  
        </tr>
      </tbody>
    </table>
  </body>
</html>
谜兔 2024-09-21 12:20:26

您的第一行有 1 个 td,colspan 为 4,但您的第二行有 2 个 td,并且 colspan 为正常?

您的标记有缺陷,请先修复此问题。

最终结果应该是什么样子?
现在的样子?

Your first row is has 1 td with a colspan of 4, but your second row is 2 td's both with a normal colspan?

Your mark up is flawed, fix this first.

What is the end result supposed to look like?
The way it looks now?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文