html - <tr >'s aren' t 创建新行

标签 html css html-table

出于某种原因,我的表格行间距不正确,只是将新行覆盖在旧行上。我得到的不是 2 行表,而是 1 行表,其中 2 行相互重叠。这是我的代码的相关部分:

<table id="points-list-wrapper">
    <tr>
        <td>
            <p class="name">Test</p>
            <p class="amount">597<img class="icon"src="icon.png"></img></p>
        </td>
    </tr>
    <tr>
        <td>
            <p class="name">Another test!</p>
            <p class="amount">0<img class="icon"src="icon.png"></img></p>
        </td>
    </tr>
</table>

以及相关的CSS...

#points-list-wrapper {
    position:absolute;
    margin-left:auto;
    margin-right:auto;
    top:20%;
    left:0;
    right:0;
    bottom:0;
    height:auto;
    width:50%;
    border:5px solid white;
}
td {
    height:100px;
}
tr {
    height:100px;
}

最终结果是表行重叠,就好像它们是 position:absolute 一样。

表格本身是绝对定位的,但这不应该影响其中的行,对吧?我在这里错过了什么。

提前致谢。

最佳答案

您绝对将所有内容定位在表格单元格中。最近的 relative 定位祖先的绝对定位。

.td 更改为:

td {
  height: 100px;
  position:relative;
}

https://jsfiddle.net/hdsbgsu9/1/

基本位置教程:http://learnlayout.com/position.html

确保修复所有其他无效的 html 问题。

关于html - <tr >'s aren' t 创建新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38448283/

相关文章:

javascript - 在 jsson 图像 slider 之间切换(显示一个,隐藏其他)

html - 我如何垂直对齐此包装内的中间 div2 和 div3?

html - 带有 rowspan 的粘性 td(标题)

html - 将鼠标悬停在 <ul> 上时,我希望显示另一个 <ul>

javascript - 我的 Bootstrap 轮播 slider 不工作

html - 将元素与 flexbox 中的底部对齐,而不使用位置 :absolute

php - 带 if 条件的默认个人资料图片

html - 使用 CSS 在特定宽度内安装损坏的 html 表格

html - 表格中的标签重叠

html - 为什么 <li> 之间有空格?