Skip to content

Instantly share code, notes, and snippets.

@Gesugao-san
Forked from rgoj/borderless-table.html
Last active July 14, 2021 09:08
Show Gist options
  • Save Gesugao-san/6515102c86184221213758b7f1b27236 to your computer and use it in GitHub Desktop.
Save Gesugao-san/6515102c86184221213758b7f1b27236 to your computer and use it in GitHub Desktop.
Examples of creating a table without borders
<!-- STARTING POINT: A simple table that will have borders -->
<table>
<tbody>
<tr>
<td>Column One</td>
<td>Column One</td>
</tr>
<tr>
<td>Content of column one</td>
<td>Content of columnt two</td>
</tr>
</tbody>
</table>
<!-- EXAMPLE 1: To remove the borders, you can add a style tag to the above example -->
<!-- Note the "!important" which ensures this style overrides other styles on the page! -->
<style>
table, tbody, td, th, tr {
border: none !important;
}
</style>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Column One</td>
<td>Column One</td>
</tr>
<tr>
<td>Content of column one</td>
<td>Content of column two</td>
</tr>
</tbody>
</table>
<!-- EXAMPLE 2: Using a table id (BEST OPTION) -->
<!-- The above will have the disadvantage of affecting every single table on the page, to avoid that
we can add an id to the table, this will also allow as to not use "!important" by increasing what's
called the specificity of our style -->
<style>
table#example-table, tbody, td, th, tr {
border: none;
}
</style>
<table id="example-table">
<tbody>
<tr>
<td>Column One</td>
<td>Column One</td>
</tr>
<tr>
<td>Content of column one</td>
<td>Content of column two</td>
</tr>
</tbody>
</table>
<!-- EXAMPLE 3 Adjusting the style of each cell separately -->
<!-- This is perhaps the simplest of the approaches - it doesn't require a separate style tag, but it does require
adjusting the style of every cell separately -->
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border: none">Column One</td>
<td style="border: none">Column One</td>
</tr>
<tr>
<td style="border: none">Content of column one</td>
<td style="border: none">Content of column two</td>
</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment