html - 位置 :absolute inside position:relative doesnt work

标签 html css

我有 table 和 tr 我设置了 tr position:relative 并且我在 tr 中添加了 span 元素并给它 position:absolute 和 left:0 但它相对于 html 的定位不是我的 tr 元素

table {
  border-collapse: collapse;
}

td {
  width: 200px;
  height: 60px;
  border: 1px solid black;
}

tr {
  border: 1px solid blue;
  position: relative;
  height: 60px;
  display: block;
}

.remove {
  display: inline-block;
  position: absolute;
  left: 0;
}
<table style="border:1px solid black;">
  <th>Name</th>
  <th>Logo</th>
  <tr>
    <td>Name</td>
    <td>Logo</td>
    <span class="remove">This should be on left side</span>
  </tr>
  <tr>
    <td>Namer</td>
    <td>Logo</td>
  </tr>
</table>

最佳答案

因为你在表格布局中使用了span标签,使得span在表格之外。对元素使用 td 标签。

table {
  border-collapse: collapse;
}

td {
  width: 200px;
  height: 60px;
  border: 1px solid black;
}

tr {
  border: 1px solid blue;
  position: relative;
  height: 60px;
  display: block;
}

.remove {
  all:initial;
  position: absolute;
  left: 0
}
<table style="border:1px solid black;">
  <th>Name</th>
  <th>Logo</th>
  <tr>
    <td>Name</td>
    <td>Logo</td>
    <td class="remove">This should be on left side</td>
  </tr>
  <tr>
    <td>Namer</td>
    <td>Logo</td>
  </tr>
</table>

关于html - 位置 :absolute inside position:relative doesnt work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58252020/

相关文章:

javascript - document.querySelector() 不起作用

html - 在 html 和 css 中垂直不透明层的图像

css - 多个背景位置

jquery - 向上或向下移动滚动条

html - 更改 Jquery 移动元素的大纲/边框

php - 使用 php 在 head 标签内设置一个 css 属性

html - 如何在 asp.net-mvc 中的 html 文本框上设置禁用属性?

javascript - 首先将 React 组件编写为一个 HTML 文件,然后将它们转换为组件是不是更好?

php - 内联生成的图像超出长度

c# - 即使使用 @import 也捆绑 css