gpt4 book ai didi

html - 使用CSS将按钮与表格中的一行对齐

转载 作者:太空狗 更新时间:2023-10-29 14:18:32 25 4
gpt4 key购买 nike

我正在尝试开发一个可用于编辑数据库信息的表(对于非数据库用户)。这是我所拥有的(对于 html):

<table id="myTable" cellspacing='0'>
<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
<tr id='1'><td>1</td><td>1</td><td>2</td>
<td style=" table-layout:fixed">
<div style="width:0px;overflow:visible;position:relative">
<a style="display:block;position:relative;left:20px">-</a>
</div>
</td>

</tr>
<tr id='2' class='even'><td>3</td><td>5</td><td>8</td></tr>
<tr id='3'><td>13</td><td>21</td><td>34</td></tr>
<tr id='4' class='even'><td>55</td><td>89</td><td>144</td></tr>
<tr id='5'><td>233</td><td>377</td><td>610</td></tr>
</table>
<input class="addRow" type="button" value="+">
</table>

这是 CSS:

table {
background: #E0F5F9;
margin-left: 20px;
margin-right: 20px;
margin-top: 20px;
margin-bottom: 0px;
border-style: solid;
border-width: 2px;
border-color: #1C9CBC;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
}

table th {
padding:4px 10px;
background: #A8A8A8;
}

table td {
background:#fff;
padding:2px 10px 4px 10px;
}

div.editableTable {
display: inline;
}

input.addRow {
margin-left: 10px;
border: solid 2px #1C9CBC;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
padding-left: 5px;
padding-right: 5px;
background: #A8A8A8;

}

table tr.even td {background:#98E6F9}
table tr td {
background: #E0F5F9;
}

table tr.editing td {
background: #FF0000;
}

table tr.selectedEven td {
background: #98E6F9;
border-left-width: 0px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
}

table tr.selectedEven td:first-child {
border-left-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
-moz-border-radius-topleft:10px;
-moz-border-radius-bottomleft:10px;
-webkit-border-bottom-left-radius:10px;
border-bottom-left-radius:10px;
-webkit-border-top-left-radius:10px;
border-top-left-radius:10px;
}

table tr.selectedEven td:last-child {
border-left-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
-moz-border-radius-topright:10px;
-moz-border-radius-bottomright:10px;
}

table tr.selectedEven td:last-child {
border-left-width: 0px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 1px;
border-style: solid;
border-color: #03C100;
}

table tr.selected td {
/* background: #E0F5F9; */
border-left-width: 0px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
}

table tr.selected td:first-child {
border-left-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
-moz-border-radius-topleft:10px;
-moz-border-radius-bottomleft:10px;
-webkit-border-bottom-left-radius:10px;
border-bottom-left-radius:10px;
-webkit-border-top-left-radius:10px;
border-top-left-radius:10px;
}

table tr.selected td:last-child {
border-left-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 0px;
border-style: solid;
border-color: #03C100;
-moz-border-radius-topright:10px;
-moz-border-radius-bottomright:10px;
}

table tr.selected td:last-child {
border-left-width: 0px;
border-top-width: 1px;
border-bottom-width: 1px;
border-right-width: 1px;
border-style: solid;
border-color: #03C100;
}

table tr:last-child td:first-child {
-moz-border-radius-bottomleft:10px;
-webkit-border-bottom-left-radius:10px;
border-bottom-left-radius:10px}

table tr:last-child td:last-child {
-moz-border-radius-bottomright:10px;
-webkit-border-bottom-right-radius:10px;
border-bottom-right-radius:10px
}

而且,这是它的样子: Table design, second try

这很好,只是右侧的删除按钮与行有点偏离。这意味着一旦我们添加了 ~13 或 14 行,删除按钮就会远离它要删除的行。因此,当用户点击删除时,他们不清楚哪一行将被删除。

我想找到一些方法,使我能够使用 CSS 将一个按钮(或在本例中为几个按钮)与相关表格的行对齐。这可能吗?我最初尝试(但没有成功)在没有第二个表的情况下执行此操作,但这导致我遇到了当前情况,我在实际包含数据的表的右侧有一个用于对齐目的的表。

我面临的最大问题是我似乎无法弄清楚如何将某些内容与表格中的一行对齐。我可能可以用 jQuery 来完成,但这似乎是在用锤子来解决问题。我承认我在 CSS 方面不如在编程方面经验丰富,所以我通常倾向于查看编程答案。有人可以帮我弄清楚如何正确对齐这些按钮吗?

谢谢!

最佳答案

您可以尝试将按钮放在最后一个 <td> 中在行中,然后将其向右浮动,并提供足够大的负右边距以将其移出表格;您还需要在表格上留出一个正的右边距,以确保为按钮留出空间。

例如:

<table>
<tbody>
<tr>
<td>kdsjfkdsl fds</td>
<td><span class="killer">X</span>Appropriately architect 24/365 internal or "organic" sources after fully tested portals. Monotonectally leverage existing an expanded array of action items before resource maximizing growth strategies. Proactively drive orthogonal ROI before sustainable relationships.</td>
</tr>
<tr>
<td>2193485798435</td>
<td><span class="killer">X</span>Enthusiastically deploy team building data with e-business internal or "organic" sources. Enthusiastically negotiate diverse models for transparent communities. Intrinsicly disseminate just in time markets before vertical paradigms. Authoritatively brand performance based web-readiness for error-free growth strategies. Energistically empower customer directed markets with quality data. Distinctively productivate backward-compatible potentialities before prospective technology.</td>
</tr>
</tbody>
</table>

还有一点 CSS(用颜色来标明所有东西在哪里):

table {
margin-right: 2em;
}
td {
padding: 5px;
border: 1px solid green;
}
span.killer {
float: right;
margin-right: -1.5em;
color: red;
font-weight: bold;
}

还有 jsfiddle:http://jsfiddle.net/ambiguous/RE8rK/

我从空中挑选边距来说明效果,我将计算正确的值由您来决定。

关于html - 使用CSS将按钮与表格中的一行对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4981888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com