我的情况如下:
<body>
<form>
<input type="text" />
<input type="submit" />
</form>
<table>
...
</table>
</body>
table
不在 form
中,而是作为同级。但是,我想将它放在 form
中的两个输入元素之间。由于表的大小是可变的,我不能直接给submit
的top
样式赋一个固定的值。相反,submit
的位置必须根据 table
的末尾(即低于几像素)。
最佳答案
最后我发现了一种只用 CSS 来做到这一点的方法,如下所示:
HTML
<body>
<form>
<input type="text" />
<input type="submit" />
</form>
<table>
<thead></thead>
<tbody>
<tr>
<td>table data 1</td>
<td>table data 2</td>
</tr>
<tr>
<td>table data 1</td>
<td>table data 2</td>
</tr>
</tbody>
</table>
</body>
CSS
body {
position: relative;
}
input {
display: block;
}
input[type="submit"] {
position: absolute;
bottom: 0;
}
table {
padding-bottom: 20px;
}
关于html - 如何在它的两个 child 之间插入它的下一个兄弟元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57375507/