- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用 CSS 设计 HTML 表格的样式。我需要能够通过 CSS 隐藏单个单元格的内容,因为在打印布局(或任何其他样式表)中它们的内容必须是可见的。该表有一个 <thead>
和一个 <tbody>
其中的部分,沿着每个 <tr>
, <th>
和 <td>
,对它们应用边框,这样无论我隐藏什么,边框(甚至是外部边框)都会始终显示。
在我的样式表中,我设置了 border-collapse: collapse;
并用 visibility:hidden;
隐藏我想隐藏的单元格,它在大多数浏览器上运行良好,但 Google Chrome 除外(以及 Firefox 中的一些小显示故障,但我认为它们来自宽度的百分比......)。
我还创建了一个这种行为的例子:
table.example {
width:100%;
border-collapse: collapse;
}
table.example td{
padding: 2px;
}
table.example .number {
text-align:right;
}
table.example .null{
visibility:hidden;
}
table.example .number.negative{
color:red;
}
table.example .Date{
text-align:center;
}
table.example th{
background-color: #dedbde;
}
table.example, th.example, td.example,.example thead,.example tbody{
border: 1px solid #a5a6a5;
}
#Demo1 .hideme.Col1,
#Demo1 .hideme.Col2 {
visibility:hidden;
border: 0;
}
#Demo1 {
width: 50%;
}
.Col1 {
width: 4%;
}
.Col2, .Col3, .Col4 {
width: 32%;
}
<table class="example" id="Demo1">
<thead>
<tr class=" example">
<th class="Col1 example"></th><th class="Col2 example">Title1</th><th class="Col3 example">Title2</th><th class="Col4 example">Title3</th>
</tr>
</thead><tbody>
<tr class="r1 example odd first">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 2865 </a></td><td class="Col3 example Date">10.06.2011</td><td class="Col4 example Date">10.07.2011</td>
</tr><tr class="r2 example even">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 2864 </a></td><td class="Col3 example Date">10.06.2011</td><td class="Col4 example Date">10.07.2011</td>
</tr><tr class="r3 example odd">
<td class="Col1 example hideme"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example hideme"><a href="#" class="detaillink"> 2863 </a></td><td class="Col3 example hideme Date">10.06.2011</td><td class="Col4 example hideme Date">10.08.2011</td>
</tr><tr class="r4 example even">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 2863 </a></td><td class="Col3 example Date">10.06.2011</td><td class="Col4 example Date">10.08.2011</td>
</tr><tr class="r5 example odd">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 2299 </a></td><td class="Col3 example Date">10.05.2011</td><td class="Col4 example Date">10.06.2011</td>
</tr><tr class="r6 example even">
<td class="Col1 example null"></td><td class="Col2 example null"></td><td class="Col3 example Date null"></td><td class="Col4 example Date null"></td>
</tr><tr class="r7 example odd">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 1249 </a></td><td class="Col3 example Date">10.03.2011</td><td class="Col4 example Date">10.04.2011</td>
</tr><tr class="r8 example even">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 1248 </a></td><td class="Col3 example Date">10.03.2011</td><td class="Col4 example Date null"></td>
</tr><tr class="r9 example odd">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example null"></td><td class="Col3 example Date">10.02.2011</td><td class="Col4 example Date">10.03.2011</td>
</tr><tr class="r10 example even last">
<td class="Col1 example"><img src="image.png" alt="test" height="15px" width="15px"></td><td class="Col2 example"><a href="#" class="detaillink"> 563 </a></td><td class="Col3 example Date">10.02.2011</td><td class="Col4 example Date">20.03.2011</td>
</tr>
</tbody>
</table>
如您所见,如果您尝试这段代码,它甚至会将所有单元格隐藏到一个小空间的行折叠起来。
这个问题对我当前的元素来说并不是真正的关键,因为大多数用户将使用 Internet Explorer,但由于我找不到任何解决方案并且这个问题可能会影响我将来(而且我确定其他人已经遇到过这个问题),我真的很想知道为什么会这样。
最佳答案
更新 1
如果你的TD只显示文字,你可以试试这个
text-indent:-9999px;
虽然不确定浏览器兼容性,但它应该只影响内联元素。无需通过此删除可见性。
在每个单元格中放置一个 div,这个 div 将包含您现在单元格中的元素,然后将 visibility:hidden
设置为仅该 div。
例子
<tr class="r2 example even">
<td class="Col1 example">
<div>
what you want to hide here...
</div>
</td>
</tr>
关于html - 为什么在设置 "visibility:hidden;"和 "border-collapse: collapse;"时表格单元格边框在 Google Chrome 中消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6469560/
有没有办法像 super 速记样式一样在 CSS 中组合 border-top,border-right,border-left,border-bottom。 例如: border: (1px sol
这个问题在这里已经有了答案: Combining border-top,border-right,border-left,border-bottom in CSS (4 个答案) 关闭 3 年前。
所以,我是那些以始终使用最新版本的浏览器而自豪的人之一(当然 Internet Explorer 除外 - 我说的不是那个浏览器)。 我遇到了 this awesome CSS3 website详细介
border-top-color 是 #9b9c9d 而 border-bottom-color 是 #f6f9fc .渐变旨在在border-left 和border-right 上将顶部颜色过渡到
我将开始开发一个新网站,并准备处理浏览器用于计算元素宽度和高度的不同方法 (box model stuff)。不知何故,我想到了:如果我只是将 box-sizing 应用于网站中的所有元素会怎么样?
这是 fiddle :http://jsfiddle.net/3Ys2d/ CSS div{ border: solid 3px blue; border-left-color: re
这个接缝很容易,但我还没有找到任何方法来做到这一点。我有 3 个 div(但解决方案必须适用于 n 个 div),如下图所示: |分区 1 ||分区 2 ||第 3 部分 | 例如: 我想要这样的普通
由于视网膜显示器具有如此高的像素密度,因此在这些显示器上 1 像素的边框看起来非常大。正如 Brad Birdsall 所建议的,CSS box-shadow属性可用于创建“0,5 px”边框,在
我可以这样写边框的样式: border: 2px solid #DDDDDD; 或者像这样: -moz-border-bottom-colors: none; -moz-border-left-col
当在已经有 1px 边框的 div 中覆盖 border-bottom 的大小时,Firefox 和 Chrome 呈现 border-left 和 border-right 不正确: HTML C
我是CSS3新手,最近在学习border-image属性,在看W3C文档的时候: http://dev.w3.org/csswg/css-backgrounds/#border-image-width
我正在尝试在使用 border-radius 属性的 div 上使用 border 属性。 这是我的 CSS: #page { border: 1px solid #beb2b2; w
我只想在已经具有顶部和底部边框(1px 纯灰色)的 div 上添加一个左边框(5px 纯蓝色)。我希望 border-left 位于 border-top 和 border-bottom 之上,但浏览
我有一个使用 border-radius 的带有圆 Angular 的流体宽度 div,以及 div 一侧的大边框,颜色不同。 当浏览器窗口足够小时,所有边框都会正常运行。但是,当我放大窗口大小时,我
导致“错误”的 Css: div { width: 100px; height: 100px; background-color: transparent; box-s
Border-bottom长度小于border-right怎么办? img { border-bottom: 5px solid #02a8d8; border-right:1px s
我是一名优秀的程序员,十分优秀!