如何制作具有 100% 宽度和内部边框的 HTML 表格?
如果您制作一个宽度为 100% 的普通表格并为单元格提供一些边框,则边框当然会围绕所有单元格的所有边缘。但是,如果您想要单元格带有阴影但边框“清晰”(与表格包含元素相同的颜色)的表格,该怎么办?在这种情况下,您可能希望边框出现在表格单元格的内部边缘,而不是外部边缘。
如果左右都有空间,您可以使表格的负边距等于单元格边框的宽度。这将使左侧齐平,但在 100% 宽度下,右侧不会完全到达右侧。如果在此设置中边框为 3 像素,则右侧将短 6 像素。
如果您使用表格的绝对宽度,您可以处理这个问题,但是如果您需要使用%宽度怎么办?
If you make a normal table with 100% width and give the cells some borders the borders will of course go around all edges of all cells. But what if you want tables where the cells are shaded but the borders are "clear" (the same colour as the containing element of the table). In this case you probably want borders to appear on the internal edges of table cells but not on the outside edges.
If there is room on the right and left you can make the table have negative margins equal to the width of the cell borders. That will make the left side flush but at 100% width the right side won't reach fully to the right. If you have 3px borders in this setup then the right side will be 6px short.
You can deal with this if you are using absolute widths for your tables but what if you need to use a % width?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种仅使用 CSS 选择器的表格内部边框的 CSS 方法,应该在 IE7 中可用:(
由 Sass 提供的奇怪缩进。)
必需的 jsFiddle 链接:http://jsfiddle.net/inerdial/KzdUV/2/
A CSS way to do only internal borders of a table that uses CSS selectors that should be available in IE7:
(Wonky indentation courtesy of Sass.)
Obligatory jsFiddle link: http://jsfiddle.net/inerdial/KzdUV/2/