Ric*_*d_G 1 html html-table sass
我正在尝试完成格式化动态构建的表.在最后一页上,当表格稀疏时,因为填充表格所需的行数少于表格,所以行显示在表格空间的底部而不是顶部.我试图纠正这个失败的原因.如何在顶部显示这些行?
它似乎并不重要,但该表是由will_paginate Ruby gem构建的.我说没关系,因为当我查看HTML时,它只是一张桌子.没有任何东西能够实现这一目标.表格大小格式化为显示10行.如果只有3个,它们就像你期望的那样被列为3行.所以,我认为这只是一个HTML/CSS格式问题.
表格显示:

SCSS:
.feeds {
list-style: none;
margin: 0;
text-align: left;
table-layout: fixed;
width: 700px;
height: 250px;
overflow: auto;
vertical-align: top;
li {
overflow: auto;
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:last-child {
border-bottom: 1px solid $grayLighter;
}
}
table, thead, th, tr, tbody, tfoot {
vertical-align: top;
}
td {
vertical-align:top;
height: 1ex;
overflow-x: auto
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<table class="feeds">
<tbody><tr>
<th id="url_cell"><a class="sortfield asc" href="/feeds?commit=Search&direction=desc&search=&sort=feed_url&utf8=%E2%9C%93">URL</a></th>
<th><a href="/feeds?commit=Search&direction=asc&search=&sort=feed_etag&utf8=%E2%9C%93">Etag</a></th>
<th><a href="/feeds?commit=Search&direction=asc&search=&sort=feed_update&utf8=%E2%9C%93">Update date</a></th>
</tr>
<tr>
<td id="url_cell"><a href="http://www.skalith.net/rss">http://www.skalith.net/rss</a></td>
<td id="etag_cell">RZWAFDMVHPXHWECK</td>
<td id="update_cell">August 5, 2013</td>
</tr>
<tr>
<td id="url_cell"><a href="http://www.viva.name/rss">http://www.viva.name/rss</a></td>
<td id="etag_cell">KFIEQYAUWMUHUJNY</td>
<td id="update_cell">August 5, 2013</td>
</tr>
</tbody></table>
Run Code Online (Sandbox Code Playgroud)
标题行是垂直填充空格(这是它应该做的因为你的table-layout.如果你用它包裹<thead>,然后只用<tbody>它包裹表的主体将正确对齐它.但是,因为你有table-layout: fixed,有height: 250px,剩余的行将增长以弥补差异.
请参阅:http://codepen.io/chrisrockwell/pen/gGmFq
如果没有完整的行集,你可以在表中添加一个类吗?这样你就可以删除高度声明.
其他选择:
我猜你需要有一个设定的高度,但如果不是,你可以删除它.
将表包裹起来并将<div>高度和溢出分配给div:
<div class="wrap">
<table class="feeds"></table>
</div>
Run Code Online (Sandbox Code Playgroud)
.wrap {
height: 250px;
overflow: auto;
}
table {
/* just remove the height and overflow */
}
Run Code Online (Sandbox Code Playgroud)
以下是选项2的示例:http://codepen.io/chrisrockwell/pen/wpyfI