How to remove spaces between cells in a html table

旧城冷巷雨未停 提交于 2019-12-04 06:19:22

The browsers are not telling you that your border-spacing style is overridden by the user agent style sheet. Instead, they may indicate that inheritance does not take place for it. This is simply caused by the fact that some style sheet sets the property on the element.

The reason why your rule is not applied to the inner table element is that it does not match any of your selectors. The selector

table.tableGroup > tr > td > table

does not match it, because a tr element is never a child of table even if might appear to be. By HTML syntax, there is an intervening tbody element, even if its start and end tag are missing. The following selector would match:

table.tableGroup > tbody > tr > td > table

Of course, a mere table selector would do the job as well, provided that you want all table elements to be styled by the rule.

You can simply use border-collapse: collapse; or even border-spacing: 0; is fine

table { /* Will apply to all tables */
    border-spacing: 0;
    /* OR border-collapse: collapse; */
}

Demo

You can easily override the useragent stylesheet with a simple element selector.


If you want to normalize the styles, you should use CSS Reset


Coming to your selector which is seems dirty to me, as yo are targeting the table with class .tableGroup and the table nested under that

table.tableGroup, table.tableGroup > tr > td > table {
    border-spacing: 0px;
}

So you better use

table.tableGroup, 
table.tableGroup table {
   border-spacing: 0;
}

you need to add (border="0" cellpadding="0" cellspacing="0") Table tributes in every table tag

example

<table border="0" cellpadding="0" cellspacing="0">

*example with your classes *

<table border="0" cellpadding="0" cellspacing="0"  class="tableGroup">

Try this

table {
    border-spacing:0px; 
}

works by using css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!