【发布时间】:2019-10-16 05:30:47
【问题描述】:
我有一个样式表,我正在构建列大小调整和其他功能。这是我的代码(可在that Fiddle 获得):
<div class="ux-data-table">
<div class="ux-data-table-inner">
<table>
<thead>
<tr>
<th class="ux-data-table-th" style="width: 20px; min-width: 20px; max-width: 20px;">
<span class="ux-data-table-th-title">
<input type="checkbox" value="on">
</span>
<div class="ux-data-table-th-grip">
</div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Name</span>
<span class="ux-data-table-th-icon-spacer"></span>
<span class="fa fa-long-arrow-up"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Description</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Property 1</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Property 2</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Property 3</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Property 4</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
<th class="ux-data-table-th" style="width: 300px; min-width: 300px; max-width: 300px;">
<span class="ux-data-table-th-title">Property 5</span>
<span class="ux-data-table-th-icon-spacer"></span>
<div class="ux-data-table-th-grip"></div>
</th>
</tr>
</thead>
<tbody class="ux-data-table-nodata">
<tr>
<td colspan="8">No data found.</td>
</tr>
</tbody>
</table>
</div>
</div>
CSS
.ux-data-table {
width: auto;
max-width: 100%;
height: calc(100vh - 300px);
overflow: auto;
float: left;
}
.ux-data-table-inner {
position: relative;
}
.ux-data-table table {
width: 100%;
}
.ux-data-table table,
.ux-data-table th,
.ux-data-table td {
border-style: solid;
border-width: 1px;
border-color: blue;
border-collapse: collapse;
color: black;
background-color: white;
text-align: left;
font-weight: normal;
font-size: 12px;
padding: 5px;
}
.ux-data-table thead {
position: absolute;
}
.ux-data-table tbody {
margin-top: 20px;
display: block;
}
.ux-data-table table thead tr th {
letter-spacing: 1px;
}
.ux-data-table table tr:hover td {
background-color: #f0f0ff;
}
.ux-data-table-th-icon-spacer {
padding-left: 5px;
}
.ux-data-table-th-title {
cursor: n-resize;
vertical-align: middle;
}
.ux-data-table-th {
position: relative;
}
.ux-data-table-th-grip {
width: 5px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
cursor: col-resize;
}
.ux-data-table-clear {
clear: both;
}
.ux-data-table-checkbox-grayed {
filter: invert(25%);
}
.ux-data-table-selected-cell td {
background-color: #f0ffff;
}
.ux-data-table-nodata {
position: initial;
display: table-row-group;
width: 100%;
}
“grips”将与 javascript 代码一起用于列大小调整,并且工作正常(只是告诉无法从 HTML 中删除夹点)。同样的,在接受点击表格排序的列上也有排序图标。
标题是分离的,因此在滚动运动中标题保持在 div 的顶部。
当表格上有数据时,表格可以正常工作。
现在我想在表格没有数据时显示一条消息,例如“未找到数据”。我需要在我的 8 个专栏中传播该信息。
我使用了 colspan 功能,但我的问题是 colspan 没有显示在表格的全部 8 列中,而仅显示在前 2 列中。
我需要一种方法使“未找到数据”行显示在所有 8 列中。我无法更改原始 CSS,因为整个表格都在工作(调整列大小、样式、分离标题等)。列的宽度也不是固定的(在这段代码中它们是固定的,但是它们是动态构建的,所以对宽度求和并不能解决问题)。
类 'ux-data-table-nodata' 不起作用,因为不知何故宽度被限制在第二列。
如何使“未找到数据”列水平扩展到 8 列?
【问题讨论】:
-
您确定要 7 列吗?
<thead>中有 8 列,因此您应该在<tbody>中将<td>添加到<tr>,将colspan更改为 8,在< thead>中删除<th>或应用 @987654332 @ 到第一个或最后一个th -
@zer00me:当然,是 8 列!!我忘记了选择列……已编辑并更正……
-
你正在使用 SASS?请以编译后的形式发布 CSS。
-
是的,我正在使用 SASS,但帖子包含生成的 CSS(我刚刚更正了一项引用 SASS 颜色的项目)。
-
什么是
position:init?
标签: html css html-table