0

I copied the table code from Bootstrap and set each of the rows to have its own background color, but there is white space in between each 1 and I do not know why.

I set all the border, margins and paddings to 0 for all the "tr"s, "tbody" and the "thead."

Question: What can I do in order to prevent the white spaces appearing around table cells?

#C1{

  margin-top: 40px;
  width: 75%;
  border: 1px solid black;
  padding: 0px;
}
.table-red{
  background-color: red;
  color: #ffffff
}
.table{
  margin-bottom: 0px;
  padding: 0px;
}

.table-striped tbody tr:nth-of-type(even){

    background-color: red;
    color: white;

}
.table-striped tbody tr:nth-of-type(odd){
    background-color: blue;
    color: white;
    border: 0;
}
thead{
    background-color: green;
    border: 0px;
    margin-bottom: 0px;
    margin-top: 0px;
}
th{
    border: 0px;
}
tbody{
    margin-top: 0px;

}   
 <div class="container" id="C1">
    <table class="table table-striped">
      <thead >
        <tr>
          <th scope="col">#</th>
          <th scope="col">First</th>
          <th scope="col">Last</th>
          <th scope="col">Handle</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Larry</td>
          <td>the Bird</td>
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
 </div>

The white space should disappear

enter image description here

Feelsbadman
  • 1,163
  • 4
  • 17
  • 37
Vamsi Krishna
  • 69
  • 1
  • 9
  • Possible duplicate of [How to remove unwanted space between rows and columns in table?](https://stackoverflow.com/questions/2279396/how-to-remove-unwanted-space-between-rows-and-columns-in-table) – Feelsbadman Jan 03 '19 at 04:00

1 Answers1

3

option 1: (CSS)

The border-collapse property sets whether table borders should collapse into a single border or be separated as in standard HTML.
The border-spacing property sets the distance between the borders of adjacent cells.
table {
    ...
    border-spacing:0;
    border-collapse:collapse;
}


option 2: (HTML)

The cellspacing attribute specifies the space, in pixels, between cells.

<table .. cellspacing="0"> .. </table>

opt1: https://www.w3schools.com/cssref/pr_border-collapse.asp
& https://www.w3schools.com/cssref/pr_border-spacing.asp

opt2: https://www.w3schools.com/tags/att_table_cellspacing.asp

EDIT: OP had bootstrap files fetched from a CDN and there were 2 css rules which added borders:

FILE: _tables.scss LINE: 5

.table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid #dee2e6;
}

FILE: bootstrap.css LINE: 1524

.table td, .table th {

    padding: .75rem;
    vertical-align: top;
    border-top: 1px solid #dee2e6;

}

These can easily be overriden by adding the following to the default css file:

.table thead th { 
    border-bottom: none !important; 
}
.table td, .table th { 
    border-top:none !important; 
}
Feelsbadman
  • 1,163
  • 4
  • 17
  • 37