- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
所以我可以有一个标题行固定在顶部的可滚动表,我将标题分隔到单独的 div 中的它们自己的表中。下面的 div 包含表格数据。表格的内容各不相同,因此我希望能够将顶部表格与下方行的间距和宽度同步,以便标题准确对齐。我该怎么做?
[header 1|header 2|header3]
[cell1 | cell2 | cell3]
这样:
[header 1 | header 2| header 3]
[cell1 | cell2 | cell3]
最佳答案
试试这个
HTML:
<div id="tableContainer" class="tableContainer">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
<thead class="fixedHeader">
<tr class="alternateRow">
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody class="scrollContent">
<tr class="normalRow">
<td>Cell Content 1 da widim dali she se sinkne kato mu nabiem kancheto s 200000 simvola otgore</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr class="normalRow">
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr class="normalRow">
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr class="alternateRow">
<td>End of Cell Content 1</td>
<td>End of Cell Content 2</td>
<td>End of Cell Content 3</td>
</tr>
</tbody>
</table>
</div>
CSS:
body {
background: #FFF;
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
margin: 10px;
padding: 0
}
div.tableContainer {
clear: both;
border: 1px solid #963;
height: 285px;
overflow: auto;
width: 756px
}
/* Reset overflow value to hidden for all non-IE browsers. */
html>body div.tableContainer {
overflow: hidden;
width: 756px
}
/* define width of table. IE browsers only */
div.tableContainer table {
float: left;
width: 740px
}
/* define width of table. Add 16px to width for scrollbar. */
/* All other non-IE browsers. */
html>body div.tableContainer table {
width: 756px
}
/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative
}
/* set THEAD element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
display: block
}
/* make the TH elements pretty */
thead.fixedHeader th {
background: #C96;
border-left: 1px solid #EB8;
border-right: 1px solid #B74;
border-top: 1px solid #EB8;
font-weight: normal;
padding: 4px 3px;
text-align: left
}
/* make the A elements pretty. makes for nice clickable headers */
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
color: #FFF;
display: block;
text-decoration: none;
width: 100%
}
/* make the A elements pretty. makes for nice clickable headers */
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x */
thead.fixedHeader a:hover {
color: #FFF;
display: block;
text-decoration: underline;
width: 100%
}
/* define the table content to be scrollable */
/* set TBODY element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto */
html>body tbody.scrollContent {
display: block;
height: 262px;
overflow: auto;
width: 100%
}
/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/ */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
background: #FFF;
border-bottom: none;
border-left: none;
border-right: 1px solid #CCC;
border-top: 1px solid #DDD;
padding: 2px 3px 3px 4px
}
tbody.scrollContent tr.alternateRow td {
background: #EEE;
border-bottom: none;
border-left: none;
border-right: 1px solid #CCC;
border-top: 1px solid #DDD;
padding: 2px 3px 3px 4px
}
/* define width of TH elements: 1st, 2nd, and 3rd respectively. */
/* Add 16px to last TH for scrollbar padding. All other non-IE browsers. */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */
html>body thead.fixedHeader th {
width: 200px
}
html>body thead.fixedHeader th + th {
width: 240px
}
html>body thead.fixedHeader th + th + th {
width: 316px
}
/* define width of TD elements: 1st, 2nd, and 3rd respectively. */
/* All other non-IE browsers. */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */
html>body tbody.scrollContent td {
width: 200px
}
html>body tbody.scrollContent td + td {
width: 240px
}
html>body tbody.scrollContent td + td + td {
width: 300px
}
-->
这只是例证。如果需要,您可以对所有单元格进行 CSS。
关于javascript - 两个表格垂直对齐,如何同步宽度/间距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16878941/
这个问题在这里已经有了答案: Why should there be spaces around '[' and ']' in Bash? (4 个回答) 3年前关闭。 作为初学者,我没有在任何地方找
我有一个程序,我在其中输入 Java 程序来检查输入的字符串是否为回文。我有 2 个问题正在发生,我似乎一辈子都无法解决。 我已经输入了代码,这样它会告诉我它是否是一个回文,当所有小写字母不涉及空格时
table { border: 0; padding: 0; border-collapse: collapse;
我有 10 个单元格,其中第 6 个单元格的宽度必须与其他单元格不同。我试图在流委托(delegate)方法中更改它。但是从第 7 个单元格到第 10 个单元格的间距出了点问题。 func coll
我只是希望将这些新闻发布很好地隔开,以便在每次发布之间留出空隙。我在下面附上了一张图片来解释。我试图增加下面的填充,但这没有用。感谢您的帮助 .headline { position: absolut
如何使用 css 删除表格结构中烦人的单元格间距和/或填充?如果解决方案在 IE7-9、Firefox 和 Chrome 中有效,请加倍支持! 为什么CSS这么难!真让人抓狂! 最佳答案 通常,在该表
我在我正在使用的网站上设置了按钮。我想在按钮外创建一个 2px 的边框,有一点间距。请参见设计图像。 我可以创建边框,但不能创建边框之外的间距。这是当前的开发站点。按钮是第一个图形。 到目前为止我已经
我正在网站上生成元素符号列表(通过使用 jquery 自动完成功能)和我在网站中使用响应式网页设计。 我想在每个列表项后留一个空格。为此,我添加了以下 CSS: li { margin-b
我在格式化我的 HTML 页面时遇到困难。 正如您从源代码中看到的那样,它是一个表格,其中每一行都包含由我的网络应用程序动态填充的格式化记录列表。如果其中一列有空值,我想保留行的格式,所以我基本上应该
我一直致力于设计一个具有三个链接的跨移动设备宽度的设计。我不明白为什么我不能得到正确的间距。什么看起来不对劲? 设计如下: 下面是编码版本的样子: 这是我的 CSS: .b-nav-Wrapper {
我需要在 matplotlib 中生成一大堆垂直堆叠的图。结果将使用 savefig 保存并在网页上查看,所以我不在乎最终图像有多高,只要子图间隔开,这样它们就不会重叠。 无论我允许这个数字有多大,子
我需要在 matplotlib 中生成一大堆垂直堆叠的图。结果将使用 savefig 保存并在网页上查看,所以我不在乎最终图像有多高,只要子图之间有间距,不重叠即可。 无论我允许图有多大,子图似乎总是
是否可以在 BorderPane 上设置节点之间的间距? ? Swing 等效项将是 BorderLayout 上的 hgap 和 vgap . 我在文档中没有找到任何内容,我能想到的唯一可行的解
我有一个基于日历的应用 我希望用户能够通过捏合来放大和缩小日历。这是我的代码: let p = UIPinchGestureRecognizer(target: self, action: #sele
我在为 Android 编写一段代码时遇到问题。我使用的是eclipse开发环境。我想要完成的是将一周中的日子均匀地分布在表格的第一行(有六行)。我不知道如何才能使这些单词真正散开,而不是仅仅粘在一起
我有一个基于日历的应用 我希望用户能够通过捏合来放大和缩小日历。这是我的代码: let p = UIPinchGestureRecognizer(target: self, action: #sele
我该怎么做才能对齐此代码中的所有列?这是正确的还是......? import urllib.request from re import findall def determinarLlegadas
当使用垂直对齐的 BoxLayout 时,如何阻止组件随着包含的 JFrame 的增长而扩展,从而在底部留下额外的空间?我尝试了不同的布局,但很快就变得一团糟。我还尝试在面板底部添加胶水,但布局管理器
我正在尝试制作 cout #include int main() { std::cout << setw(4) << 1 << setw(4) << 2 << std::endl; } 输出
使用示例 http://developer.android.com/guide/tutorials/views/hello-tabwidget.html通过向布局添加 HorizontalScro
我是一名优秀的程序员,十分优秀!