在 HTML 中设置内部表格边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2658260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:45:43  来源:igfitidea点击:

Set inner table border in HTML

htmlcssbordercss-tables

提问by ripper234

How do I set the "inner border" - the border between different cells.

如何设置“内边框” - 不同单元格之间的边框。

By setting style attributes I manage to control the outer border, but the inner border just stays the same gray color and the same width. What attributes should I tweak to control the inner border?

通过设置样式属性,我设法控制了外边框,但内边框只是保持相同的灰色和相同的宽度。我应该调整哪些属性来控制内边框?

回答by dalgard

For ordinary table markup, here's a short solution that works on all devices/browsers on BrowserStack, except IE 7 and below:

对于普通表格标记,这里有一个简短的解决方案,适用于 BrowserStack 上的所有设备/浏览器,IE 7 及以下版本除外:

table { border-collapse: collapse; }

td + td,
th + th { border-left: 1px solid; }
tr + tr { border-top: 1px solid; }

For IE 7 support, add this:

对于 IE 7 支持,添加以下内容:

tr + tr > td,
tr + tr > th { border-top: 1px solid; }

A test case can be seen here: http://codepen.io/dalgard/pen/wmcdE

可以在这里看到一个测试用例:http: //codepen.io/dalgard/pen/wmcdE

回答by daLizard

You need to style the <td>element.

您需要为<td>元素设置样式。

Take a look at the W3C website

看看W3C网站