简体   繁体   English

透明表边框与tr背景

[英]Transparent table border with tr background

I use :nth-child(odd/even) selector to make different background for table rows for better readability. 我使用:nth-​​child(odd / even)选择器为表格行设置不同的背景,以提高可读性。 And now I have to set "border-spacing" or "border-color: transparent" for my table, to make background visible thru the space between cells. 现在,我必须为表格设置“边框间距”或“边框颜色:透明”,以使背景通过单元格之间的空间可见。 The problem is, that horizontal spacing should be different for different columns - the last column should have larger spacing than whole table (marked with red in the sample below). 问题在于,不同列的水平间距应该不同-最后一列的间距应大于整个表格的间距(在下面的示例中用红色标记)。 How can I do that? 我怎样才能做到这一点? Have no idea. 不知道。 Please help. 请帮忙。 Thank you! 谢谢!

 body { background: #3a7; } table { border-collapse: separate; border-spacing: 5px; border: 0px solid #ffffff; margin: 1em; table-layout: fixed; } td { font-size: 1rem; empty-cells: show; /*background: white;*/ padding: 0; } td.last { font-size: 1rem; empty-cells: show; /*background: white;*/ /*border-left: 20px transparent;*/ border-left: 20px solid rgba(255,0,0,0.5); } tr:nth-child(odd) { padding: 0px; margin: 0; background: #fff; color: #000; border: 0px solid transparent; overflow: visible; } tr:nth-child(even) { padding: 0px; margin: 0; background: #000; color: #fff; border: 0px solid transparent; overflow: visible; } input { border: 0px; outline: 0px transparent; background-color: transparent; color: inherit; margin: 5px; } 
 <table> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> </table> 

This should work 这应该工作

 body { background: #3a7; } td.last { font-size: 1rem; empty-cells: show; } tr:nth-child(odd) { padding: 0px; color: #000; border: 0px solid transparent; overflow: visible; } tr:nth-child(even) { padding: 0px; margin: 0; color: #fff; border: 0px solid transparent; overflow: visible; } input { border: 0px; outline: 0px transparent; background-color: transparent; color: inherit; margin: 5px; } tr:nth-child(odd) div { background: white; } tr:nth-child(even) div { background: black; } .last > div { margin-left: 20px; } 
 <table> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> <tr> <td><div><input></div></td> <td><div><input></div></td> <td class="last"><div><input></div></td> </tr> </table> 

Another option is to set the last cell's background to none and instead color the background of the input field and its border: 另一个选择是将最后一个单元格的背景设置为none然后为输入字段及其边框的背景着色:

https://jsfiddle.net/e1fnoa34/ https://jsfiddle.net/e1fnoa34/

You could make the last cell background: none , and give it padding-left: 20px . 您可以将最后一个单元格background: none ,并将其设置为padding-left: 20px Then wrap the cell's content in a DIV or SPAN and apply the background styling to the inner wrapper instead. 然后将单元格的内容包装在DIVSPAN ,并将背景样式应用于内部包装器。

Not ideal, but unfortunately you can't vary the with of the table cell spacing, and margin is ignored for table cells. 这并不理想,但是很遗憾,您不能随表格单元格间距的变化而变化,表格单元格的边距将被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM