【发布时间】:2017-05-19 12:39:12
【问题描述】:
我已经创建了一个表,并希望为用户提供删除某行的选项,但我无法将删除符号垂直居中在行内。目前,删除符号不会从底部移动表格行,我不知道如何解决这个问题,所以任何帮助表示赞赏!
用cmets在Javascript和CSS中指出了问题区域!这就是现在的样子(你可以看出,删除符号不在垂直中心):
这就是我想要的样子(photoshopped):
代码:
function createTable() {
var table = "<table><tr><td>Name<span class='special'>▲</span></td><td>Age<span class='special'>▲</span></td><td>Sex</td></tr>";
for(var i=0;i < array.length;i++){
if (array.length > 0){
table += "<tr><td>" + array[i].name + "</td>";
table += "<td>" + array[i].age + "</td>";
// THIS IS THE ROW OF THE PROBLEM
table += "<td>" + array[i].sex + "<span class='delete'><a><i class='fa fa-trash-o' aria-hidden='true'></i></a></span></td></tr>";
}
}
table += "</table>";
document.getElementById("tablePrint").innerHTML = table;
}
#tablePrint {}
table {
position:relative;
z-index:0;
overflow:hidden;
border:1px solid black;
border-radius:5px;
border-collapse: collapse;
display:block;
max-width:600px;
width:100%;
margin:0 auto;
margin-top:50px;
background-color:white;
-webkit-box-shadow: 10px 10px 15px -7px rgba(0,0,0,0.60);
-moz-box-shadow: 10px 10px 15px -7px rgba(0,0,0,0.60);
box-shadow: 10px 10px 15px -7px rgba(0,0,0,0.60);
}
tr {
color:black;
font-size:18px;
font-weight:400;
}
tr:nth-child(odd){
background-color:#C5C5C5;
}
tr:first-child {
background-color:#191919;
color:#D3D3D3;
font-size:23px;
font-weight:200;
}
tr:first-child td {
border-bottom:4px solid #696969;
}
tr:last-child td {
border-bottom:0;
}
td {
position:relative;
overflow:hidden;
width:200px;
height:auto;
padding:20px;
border-bottom:1px solid #474747;
border-right: 1px solid #474747;
}
td:last-child {
border-right:0;
}
td span.special {
display:block;
float:right;
cursor:pointer;
}
// THE PROBLEM
.delete {
position:absolute;
text-align:center;
height:64px;
width:40px;
right:0;
top:0;
bottom:0;
}
.delete a {
position:relative;
top:50%;
margin-top:-30px;
font-size
<div id="tablePrint"></div>
【问题讨论】:
标签: css html html-table row