Remove white spaces between tds

Asked

Viewed 30 times

2

Hello, I’m developing a project that uses the table structure and that in each row except the header row whenever there is a Hover on it, it gets a light gray but here to see well put a strong blue, but only that between the columns in the effect of the Hover one notices a white space and I wanted to know how to take that space?

Thanks for the answers, both work, but unfortunately only to accept a!

* {
            margin: 0;
            padding: 0;
            box-sizing:border-box;
        }
        body {
          font-family: Helvetica;
          -webkit-font-smoothing: antialiased;
        }
        ul {
          list-style-type: none;
          margin: 0;
          padding: 0;
          overflow: hidden;
          background-color: #333;
        }
        li {
          float: left;
        }
        li a {
          display: block;
          color: white;
          text-align: center;
          padding: 14px 16px;
          text-decoration: none;
        }
        li a:hover:not(.active) {
          background-color: #111;
        }
        .wellcome{
            background-color: #444;
        }
        .wc{
    padding: 14px 16px;
    font-size: 18px;
    color: white;
    text-align: center;
  }
  .active {
    background-color: #4CAF50;
  }
  .modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0,0.4);
}
.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 18%;
}
div#regit{
  width: 90%;
  margin: 10px auto;
}
div#regit table{
  width: 100%;
  padding: 10px;
}
.espca{
  border-bottom: 1px solid #ccc;
  padding: 10px;
}
div#regit table tr:hover:not(.header){
  background: blue;
}
div#select{
  cursor: pointer;
  width: 40px;
  height: 40px;
  border: 1px solid #000;
  padding: 10px;
}
.cruz{
  font-size: 18px;
  cursor: pointer;
}
.desativado{
  visibility: hidden;
}
.noselect{
  user-select: none;
}
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>SMART DNS | Controlo de Bloqueios</title>
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" media="all">
</head>
<body>
<div class="wellcome">
<p class="wc"></p>
</div>
<ul>
<li><a class="new" href="javascript:void(0)"><i class="far fa-plus-square"></i> Novo Registo</a></li>
<li><a class="list active" href="javascript:void(0)"><i class="fas fa-list"></i> Lista de Sites</a></li>
<li><a class="cats" href="javascript:void(0)"><i class="fas fa-quote-right"></i> Lista de Categorias</a></li>
<li><a class="req" href="javascript:void(0)"><i class="fas fa-network-wired"></i> Pedidos de Desbloqueios</a></li>
<li style="float:right"><a class="exit" href="javascript:void(0)"><i class="fas fa-sign-out-alt"></i> Sair</a></li>
</ul>
<div id="regit">
<table id="tabela">
<tr class="header">
<td class="espca">Selecionar</td>
<td class="espca">Pagina Web</td>
<td class="espca">Categorias</td>
</tr>
<tr>
<td class="espca"><div id="select"><label class="cruz desativado">X</label></div></td>
<td class="espca">google.com</td>
<td class="espca">Cat1, Cat2</td>
</tr>
</table>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<center>
<img src="assets/load.gif" width="100">
<p>A carregar registos!</p>
</center>
</div>
</div>
</body>
</html>

  • Was worth the force :)

2 answers

4


You have to add the property border-collapse: collapse; in <table> this will remove the "spaces" between cells.

Edit: The border-collapse: collapse; it seems that for some reason also remove the padding of table. So it may be that the best option for you really is the @sam response. But I’m going to leave that option just to let you know that tb is an alternative, even though it works differently than border-spacing

table {
    border-collapse: collapse;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Helvetica;
    -webkit-font-smoothing: antialiased;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: #111;
}

.wellcome {
    background-color: #444;
}

.wc {
    padding: 14px 16px;
    font-size: 18px;
    color: white;
    text-align: center;
}

.active {
    background-color: #4CAF50;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 18%;
}

div#regit {
    width: 90%;
    margin: 10px auto;
}

div#regit table {
    width: 100%;
    padding: 10px;
}

.espca {
    border-bottom: 1px solid #ccc;
    padding: 10px;
}

div#regit table tr:hover:not(.header) {
    background: blue;
}

div#select {
    cursor: pointer;
    width: 40px;
    height: 40px;
    border: 1px solid #000;
    padding: 10px;
}

.cruz {
    font-size: 18px;
    cursor: pointer;
}

.desativado {
    visibility: hidden;
}

.noselect {
    user-select: none;
}
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" media="all">

<div class="wellcome">
    <p class="wc"></p>
</div>
<ul>
    <li><a class="new" href="javascript:void(0)"><i class="far fa-plus-square"></i> Novo Registo</a></li>
    <li><a class="list active" href="javascript:void(0)"><i class="fas fa-list"></i> Lista de Sites</a></li>
    <li><a class="cats" href="javascript:void(0)"><i class="fas fa-quote-right"></i> Lista de Categorias</a></li>
    <li><a class="req" href="javascript:void(0)"><i class="fas fa-network-wired"></i> Pedidos de Desbloqueios</a></li>
    <li style="float:right"><a class="exit" href="javascript:void(0)"><i class="fas fa-sign-out-alt"></i> Sair</a></li>
</ul>
<div id="regit">
    <table id="tabela">
        <tr class="header">
            <td class="espca">Selecionar</td>
            <td class="espca">Pagina Web</td>
            <td class="espca">Categorias</td>
        </tr>
        <tr>
            <td class="espca">
                <div id="select"><label class="cruz desativado">X</label></div>
            </td>
            <td class="espca">google.com</td>
            <td class="espca">Cat1, Cat2</td>
        </tr>
    </table>
</div>
<div id="myModal" class="modal">
    <div class="modal-content">
        <center>
            <img src="assets/load.gif" width="100">
            <p>A carregar registos!</p>
        </center>
    </div>
</div>

3

The browser applies in table one border-spacing (space between the edges of the cells) standard 2 pixels:

inserir a descrição da imagem aqui

Just change this value to 0 using the table id:

#tabela{
   border-spacing: 0;
}

Behold:

#tabela{
   border-spacing: 0;
}

* {
            margin: 0;
            padding: 0;
            box-sizing:border-box;
        }
        body {
          font-family: Helvetica;
          -webkit-font-smoothing: antialiased;
        }
        ul {
          list-style-type: none;
          margin: 0;
          padding: 0;
          overflow: hidden;
          background-color: #333;
        }
        li {
          float: left;
        }
        li a {
          display: block;
          color: white;
          text-align: center;
          padding: 14px 16px;
          text-decoration: none;
        }
        li a:hover:not(.active) {
          background-color: #111;
        }
        .wellcome{
            background-color: #444;
        }
        .wc{
    padding: 14px 16px;
    font-size: 18px;
    color: white;
    text-align: center;
  }
  .active {
    background-color: #4CAF50;
  }
  .modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0,0.4);
}
.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 18%;
}
div#regit{
  width: 90%;
  margin: 10px auto;
}
div#regit table{
  width: 100%;
  padding: 10px;
}
.espca{
  border-bottom: 1px solid #ccc;
  padding: 10px;
}
div#regit table tr:hover:not(.header){
  background: blue;
}
div#select{
  cursor: pointer;
  width: 40px;
  height: 40px;
  border: 1px solid #000;
  padding: 10px;
}
.cruz{
  font-size: 18px;
  cursor: pointer;
}
.desativado{
  visibility: hidden;
}
.noselect{
  user-select: none;
}
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" media="all">
<div class="wellcome">
<p class="wc"></p>
</div>
<ul>
<li><a class="new" href="javascript:void(0)"><i class="far fa-plus-square"></i> Novo Registo</a></li>
<li><a class="list active" href="javascript:void(0)"><i class="fas fa-list"></i> Lista de Sites</a></li>
<li><a class="cats" href="javascript:void(0)"><i class="fas fa-quote-right"></i> Lista de Categorias</a></li>
<li><a class="req" href="javascript:void(0)"><i class="fas fa-network-wired"></i> Pedidos de Desbloqueios</a></li>
<li style="float:right"><a class="exit" href="javascript:void(0)"><i class="fas fa-sign-out-alt"></i> Sair</a></li>
</ul>
<div id="regit">
<table id="tabela">
<tr class="header">
<td class="espca">Selecionar</td>
<td class="espca">Pagina Web</td>
<td class="espca">Categorias</td>
</tr>
<tr>
<td class="espca"><div id="select"><label class="cruz desativado">X</label></div></td>
<td class="espca">google.com</td>
<td class="espca">Cat1, Cat2</td>
</tr>
</table>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<center>
<img src="assets/load.gif" width="100">
<p>A carregar registos!</p>
</center>
</div>
</div>

  • 1

    Really Sam, the border-spacing will interfere less in the "layout" he made. I left Edit in my answer that I will leave there just to be included as an option...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.